数学与位运算
来源:互联网 发布:网络锁是什么 编辑:程序博客网 时间:2024/05/18 17:04
正负 溢出 除零
https://oj.leetcode.com/tag/math/
溢出相关的问题
Integer.MAX_VALUE:2^31 - 1=2147483647
Integer.MIN_VALUE:-2^31= -2147483648
求绝对值会溢出
判断:使用long解决int溢出问题
二分查找计算中点避免溢出:m = (l + r) / 2 = l + (r - l) / 2
Java逻辑与位操作
#1数学运算
加减:
E11:https://oj.leetcode.com/problems/add-two-numbers/ (链表)
H2:https://oj.leetcode.com/problems/add-binary/ (字符串)
F3:https://oj.leetcode.com/problems/plus-one/ (数组)
乘除:
H3:https://oj.leetcode.com/problems/multiply-strings/ (字符串)
J8:https://oj.leetcode.com/problems/fraction-to-recurring-decimal/ (字符串循环小数)
J1:https://oj.leetcode.com/problems/divide-two-integers/ (比特试探) (重)
幂与开方:
J2:https://oj.leetcode.com/problems/sqrtx/ (二分查找)
J3:https://oj.leetcode.com/problems/powx-n/ (分治)
#2String格式
H4:https://oj.leetcode.com/problems/string-to-integer-atoi/
H6:https://oj.leetcode.com/problems/roman-to-integer/
https://oj.leetcode.com/problems/integer-to-roman/
J4:https://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ (逆波兰式)
#3数字pattern
J5:https://oj.leetcode.com/problems/reverse-integer/
J6:https://oj.leetcode.com/problems/palindrome-number/ (基于J5)
#4二进制bit操作
https://oj.leetcode.com/tag/bit-manipulation/
比特位累计(不同运算只是公式不同)
因为int数值大小有限,所以分治与比特位累计复杂度一样
乘法:a * 7 = a (2^2 + 2^1 + 2^0) = a<<2 + a<<1 + a<<0 (此法因为CPU可以直接移位)
a * 7 = a*(1 +2 + 4) = a + a*2 + a*4 (DP比分治加法快)
乘方:a ^ 7 = a^(1 + 2 + 4) = a * a^2 * a^4 (DP)
J3:https://oj.leetcode.com/problems/powx-n/
比特位试探 (不同运算只是公式不同)
因为int数值大小有限,所以二分查找与比特位累计复杂度一样
除法:a/b=x => a-bx=0 => 将x视为二进制数 移位相减试探
J1:https://oj.leetcode.com/problems/divide-two-integers/ (除了溢出还要小心除0;bit操作比二分查找快)
开方:a^1/2=x => a-x^2=0 =>将x视为二进制数 乘方相减试探
J2:https://oj.leetcode.com/problems/sqrtx/ (bit操作比二分查找快)
log:loga=x => a-2^x=0
比特操作
J12: https://oj.leetcode.com/problems/single-number/
J13: https://oj.leetcode.com/problems/single-number-ii/
https://leetcode.com/problems/reverse-bits/
https://leetcode.com/problems/number-of-1-bits/
一个正整数int有多少bit位为一
#5进制相关
J7:https://oj.leetcode.com/problems/excel-sheet-column-title/
https://oj.leetcode.com/problems/excel-sheet-column-number/
https://oj.leetcode.com/problems/factorial-trailing-zeroes/
J16: https://oj.leetcode.com/problems/gray-code/
#6几何
J15: https://oj.leetcode.com/problems/max-points-on-a-line/
- 数学与位运算
- 数学 模+位运算
- 运算符,位运算符,成员运算符,身份运算符,与数学函数
- 赋值运算与位运算
- hdoj4810Wall Painting【组合数学+位运算】
- hdu4810 wall painting 组合数学+位运算
- 「算法」数学和位运算
- ZOJ3870 Team Formation【位运算+数学】
- 位运算符与位运算
- 枚举与位运算
- 位运算与余数
- 二进制与位运算
- 位运算与加减法
- 位运算与子集
- 指针与位运算
- 位运算与优化
- 枚举与位运算
- 位运算与应用
- iBatis简单入门教程
- 安卓4.4上adb高权限相关几个系统属性
- spark sql基础使用范例
- Hibernate - 中文乱码
- EditText 软件键盘之间的控制
- 数学与位运算
- Windows 操作系统安全模式九大应用技巧
- 关于Wrong orientation? No orientation specified问题
- IOS及时通讯中消息的处理方式
- VLC for Android源码下载和编译 (包含其他开源项目,很全面!!!!)
- atoi()函数的实现
- Selenium2Library使用Remote功能(RobotFramework)
- Android 代码检查工具SonarQube
- php range范围数组