Saturday, September 9, 2017

LeetCode Notes

Avoiding overflow
  mid = (high - low)/2 + low; instead of mid = (high + low)/2;
Remove duplicates from array, example
        int s=1;
        for(int i=1; i<nums.size(); i++) {
            if(nums[i] != nums[i-1]) {
                nums[s] = nums[i];
                s++;
            }
        }

Fast and slow runner
  141. Linked List Cycle
Counting duplicates
  38. Count and Say      26. Remove Duplicates from Sorted Array

Greatest common divisor
int gcd(int x, int y){return y ? gcd(y, x%y) : x;}
Sum of all possible combinations
$$\sum_{k=0}^{n} C_n^k$$

No comments:

Post a Comment