摘要:
Simple DP, but notes:1. initialize the array not only for dp[i] += dp[i-1], but also dp[i] += dp[i-1] + grid[i][0];2. Clear that we are using one dime... 阅读全文
摘要:
1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i... 阅读全文
摘要:
Use two stacks :class MinStack {private: stack s, minS;public: void push(int x) { if (minS.empty() || x s;public: void push(int x) { ... 阅读全文
摘要:
Iterative: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : ... 阅读全文
摘要:
Note:Since it merged from end, so1. tmp1, tmp2 = INT_MIN2. tmp1 > tmp2 1 class Solution { 2 public: 3 void merge(int A[], int m, int B[], int n) {... 阅读全文
摘要:
Use merge two looply merge the from the queue. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNod... 阅读全文
摘要:
1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * int end; 6 * Interval() : start(0), end(0) {} 7 * ... 阅读全文
摘要:
O(m + n):Note:return rec[1] not rec[0]. 1 class Solution { 2 public: 3 double findMedianSortedArrays(int A[], int m, int B[], int n) { 4 i... 阅读全文
摘要:
1 class Solution { 2 public: 3 int maxSubArray(int A[], int n) { 4 int result = A[0], sum = A[0]; 5 for (int i = 1; i < n; i++) {... 阅读全文
摘要:
Similar to maximum sum subarray, but need a gmin to record the global minimum to handle negative numbermultiplication. 1 class Solution { 2 public: 3 ... 阅读全文