LeetCode 46. Permutations return all the possible permutations.
求组合数:运用排列组合直接解62. Unique Paths
求余的分配律 in 银联比赛之码队弟弟求和
用费马小定理+快速幂解决“除法取模“问题
求最大公约数gcd:
int gcd(int a,int b){
if(a==0)
return b;
return gcd(b%a,a);
}
快速排序的变形,可在O(n)内找到指定索引dest上的数:
void partition(int[] B, int left, int r, int dest) {
if (left >= r)
return;
int pivot = B[left];
int i = left, j = r;
while (i < j) {
for (; i < j && B[j] >= pivot; --j) {
}
if (i == j) {
break;
}
B[i++] = B[j];
for (; i < j && B[i] <= pivot; ++i) {
}
if (i == j) {
break;
}
B[j--] = B[i];
}
B[i] = pivot;
if (dest < i) {
partition(B, left, i - 1, dest);
} else if (dest > i) {
partition(B, i + 1, r, dest);
}
}
求两侧最近的更小点,用单调栈解Largest Rectangle in Histogram和trapping-rain-water
区间最值查询RangeMaximumQuery google codejam 2019 round1b第三题
线段并集等:LeetCode 57. Insert Interval和 218. The Skyline Problem