Leetcode Notes

  • 229. Majority Element II

Moore Voting: delete a pair of different numbers at one time.

Need to validate if they are larger than n/3.

  • 18. 4Sum

4Sum and 3Sum is similar. Both of them use 2Sum’s method. Fast and slow pointer from sides to center.

if(nums[i]*4>target) break;

Throw bad case as many as you can to reduce loop time.


Leave a Reply

Your email address will not be published. Required fields are marked *