原创 leetcode 2: Add Two Numbers
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(i
原创 leetcode 239: Sliding Window Maximum
Use the a deque to save numbers like a waitlist. If the window size equals to k, start the pop operation of the deque a
原创 leetcode 273: Integer to English Words
Be careful about many corner cases. class Solution { public: string numberToWords(int num) { string res;
原创 leetcode 7: Reverse Integer
class Solution { public: int reverse(int x) { int sign=1; if(x<0) { sign=-1;
原创 leetcode 4: Median of Two Sorted Arrays
Use the idea of merge sort. class Solution { public: double findMedianSortedArrays(vector<int>& nums1, vector<int>&
原创 leetcode 238: Product of Array Except Self
Learn the idea from https://leetcode.com/discuss/49667/o-n-time-and-o-1-space-c-solution-with-explanation. O(n) time an
原创 leetcode 57: Insert Interval
Loop the array once and merge the newInterval with every intervals. If it cannot be merged into any interval, just inse
原创 leetcode 240: Search a 2D Matirx II
Use binary search for those rows that might contains the target. class Solution { public: bool searchMatrix(vector
原创 leetcode 236: Lowest Common Ancestor of a Binary Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *
原创 leetcode 235: Lowest Common Ancestor of a Binary Search Tree
Use recursion. if none of root, root->left and root->right equal to p or q, return NULL. If left and right are both not