Posted on:
Last modified:
数学类问题一定要记得进位 v = v1 + v2 + carry
辗转相除法(欧几里得算法). 原理在于 gcd(a, b) == gcd(b, a % b)
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
卡特兰数,为什么除以 n+1
牛顿迭代法
格雷码
n > 0 && (n & (n - 1)) == 0
x & (mod - 1)
(x ^ y) >= 0
(a >> b) & 1
for (int s = u; s; s = (s - 1) & u)
while (n) {n = n & (n-1); count++}
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
有时候几何题也会出现在面试中。不过,毕竟是 coding interview 而不是 math interview,这部分复习的优先级不高。
© 2016-2022 Yifei Kong. Powered by ynotes
All contents are under the CC-BY-NC-SA license, if not otherwise specified.
Opinions expressed here are solely my own and do not express the views or opinions of my employer.
友情链接: MySQL 教程站