摘要:
Same with I 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * ... 阅读全文
posted @ 2015-03-21 17:27
keepshuatishuati
阅读(112)
评论(0)
推荐(0)
摘要:
Recursive. 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * ... 阅读全文
posted @ 2015-03-21 17:23
keepshuatishuati
阅读(127)
评论(0)
推荐(0)
摘要:
Exact same as I. 1 class Solution { 2 public: 3 vector getRow(int rowIndex) { 4 if (rowIndex (); 5 vector result(1, 1); 6 ... 阅读全文
posted @ 2015-03-21 17:19
keepshuatishuati
阅读(102)
评论(0)
推荐(0)
摘要:
This is simple. Just everything use current[j] += current[j-1]. But leave the first one to be "1". Then add another "1" to end. 1 class Solution { 2 p... 阅读全文
posted @ 2015-03-21 17:16
keepshuatishuati
阅读(122)
评论(0)
推荐(0)
摘要:
I am lazy so I did not clear the two dynamic allowcated . 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ... 阅读全文
posted @ 2015-03-21 17:12
keepshuatishuati
阅读(147)
评论(0)
推荐(0)
摘要:
Notes:1. If len dp(len+1, 0); 7 vector > rec(len, vector(len, false)); 8 for (int i = 0; i = 0; i--) {10 for (int j = i; ... 阅读全文
posted @ 2015-03-21 16:45
keepshuatishuati
阅读(126)
评论(0)
推荐(0)
摘要:
1 class Solution { 2 public: 3 bool isP(string s) { 4 int start = 0, end = s.size()-1; 5 while (start > &result, vector current,... 阅读全文
posted @ 2015-03-21 16:36
keepshuatishuati
阅读(123)
评论(0)
推荐(0)
摘要:
1. x/rec >= 10.2. find start and end of a number. 1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 if (x = 10) rec *= 10; 7 ... 阅读全文
posted @ 2015-03-21 15:22
keepshuatishuati
阅读(136)
评论(0)
推荐(0)
摘要:
Scanning from start to end. If find a mismatch and one is larger size, keep search from the previous char of shorter one.Finally check whether found a... 阅读全文
posted @ 2015-03-21 15:17
keepshuatishuati
阅读(141)
评论(0)
推荐(0)
摘要:
1 class Solution { 2 public: 3 int hammingWeight(uint32_t n) { 4 int result = 0; 5 while (n > 0) { 6 if (n & 1) { 7 ... 阅读全文
posted @ 2015-03-21 10:04
keepshuatishuati
阅读(93)
评论(0)
推荐(0)
摘要:
1 class Solution { 2 public: 3 void swap(int &a, int &b){int t = a; a = b; b = t;}; 4 void reverse(vector &num, int start, int end) { 5 ... 阅读全文
posted @ 2015-03-21 09:49
keepshuatishuati
阅读(125)
评论(0)
推荐(0)
摘要:
You can use N-Queens I 's method counting for the result. But it wont pass the leetcode test.Use bit operation will be much faster: 1 class Solution {... 阅读全文
posted @ 2015-03-21 09:39
keepshuatishuati
阅读(132)
评论(0)
推荐(0)
摘要:
Brute Force: 1 class Solution { 2 public: 3 bool notExist(vector rec, int level, int current) { 4 for (int i = 0; i rec, vector &result) ... 阅读全文
posted @ 2015-03-21 09:24
keepshuatishuati
阅读(124)
评论(0)
推荐(0)
摘要:
Notes:1. Dont have to allocate l1*l2, just l1+l2 is fare enough.2. remember i--, j--.3. upgrade[i+j] is += not = rec[i+j+1]/10; 1 class Solution { 2 p... 阅读全文
posted @ 2015-03-21 09:13
keepshuatishuati
阅读(145)
评论(0)
推荐(0)
摘要:
1 class Solution { 2 public: 3 string getRange(int start, int end) { 4 ostringstream oss; 5 if (start == end) { 6 oss... 阅读全文
posted @ 2015-03-21 08:13
keepshuatishuati
阅读(116)
评论(0)
推荐(0)
摘要:
Notes:1. When check left shifting, do not use continue, but break it!!! Otherwise, you wil fall into infinite loop2. Initialize the map with T, not S!... 阅读全文
posted @ 2015-03-21 08:03
keepshuatishuati
阅读(158)
评论(0)
推荐(0)
摘要:
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... 阅读全文
posted @ 2015-03-21 07:50
keepshuatishuati
阅读(181)
评论(0)
推荐(0)
摘要:
1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i... 阅读全文
posted @ 2015-03-21 07:39
keepshuatishuati
阅读(107)
评论(0)
推荐(0)
摘要:
Use two stacks :class MinStack {private: stack s, minS;public: void push(int x) { if (minS.empty() || x s;public: void push(int x) { ... 阅读全文
posted @ 2015-03-21 07:35
keepshuatishuati
阅读(145)
评论(0)
推荐(0)
摘要:
Iterative: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : ... 阅读全文
posted @ 2015-03-21 07:31
keepshuatishuati
阅读(145)
评论(0)
推荐(0)
摘要:
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) {... 阅读全文
posted @ 2015-03-21 07:26
keepshuatishuati
阅读(123)
评论(0)
推荐(0)
摘要:
Use merge two looply merge the from the queue. 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNod... 阅读全文
posted @ 2015-03-21 07:14
keepshuatishuati
阅读(137)
评论(0)
推荐(0)
摘要:
1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * int end; 6 * Interval() : start(0), end(0) {} 7 * ... 阅读全文
posted @ 2015-03-21 06:20
keepshuatishuati
阅读(119)
评论(0)
推荐(0)
摘要:
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... 阅读全文
posted @ 2015-03-21 06:13
keepshuatishuati
阅读(118)
评论(0)
推荐(0)
摘要:
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++) {... 阅读全文
posted @ 2015-03-21 05:54
keepshuatishuati
阅读(99)
评论(0)
推荐(0)
摘要:
Similar to maximum sum subarray, but need a gmin to record the global minimum to handle negative numbermultiplication. 1 class Solution { 2 public: 3 ... 阅读全文
posted @ 2015-03-21 05:51
keepshuatishuati
阅读(131)
评论(0)
推荐(0)
摘要:
Sorting solution O(nlogn): 1 class Solution { 2 public: 3 int maximumGap(vector &num) { 4 int len = num.size(), result = 0; 5 if (... 阅读全文
posted @ 2015-03-21 05:47
keepshuatishuati
阅读(132)
评论(0)
推荐(0)
摘要:
1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i... 阅读全文
posted @ 2015-03-21 05:00
keepshuatishuati
阅读(95)
评论(0)
推荐(0)
摘要:
This is the extension of Largest Rectangle in Histogram. We can just project 2D matrix to 1D array and compute it line by line. 1 class Solution { 2 p... 阅读全文
posted @ 2015-03-21 04:58
keepshuatishuati
阅读(141)
评论(0)
推荐(0)
浙公网安备 33010602011771号