Gray Code
Description The description of this problem is very vague. It is even unclear what is the gray code with 3 bits. What is worse, according to wikipedia, there do exist various ways of defining gray code. With some “guessing” work,...
Description The description of this problem is very vague. It is even unclear what is the gray code with 3 bits. What is worse, according to wikipedia, there do exist various ways of defining gray code. With some “guessing” work,...
Description https://oj.leetcode.com/problems/balanced-binary-tree/ Difficulty: 1.0/5.0 star Solution /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public:...
Description https://oj.leetcode.com/problems/remove-element/ Difficulty: 1.5/5.0 star Analysis and solution class Solution { public: int removeElement(int A[], int n, int elem) { queue<int>emptySlot; int numRemove = 0; for (int i = 0; i < n; ++ i){ if (A[i] == elem){ emptySlot.push(i);...
Description https://oj.leetcode.com/problems/merge-two-sorted-lists/ Difficulty: 0.5/5.0 star Solution /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *mergeTwoLists(ListNode *l1, ListNode...
Description https://oj.leetcode.com/problems/maximum-subarray/ Difficulty: 1.0/5.0 star Related problem: https://oj.leetcode.com/problems/maximum-product-subarray/ Resource: http://en.wikipedia.org/wiki/Kadane%27s_Algorithm Analysis This is actually a 1-D DP problem. Supposed that indicates the maximum summation you can get with element involved, the maxSum[i] = max(A[i], maxSum[i] + A[i]) When it comes...