摘要: 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 阅读(104) 评论(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 阅读(122) 评论(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 阅读(99) 评论(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 阅读(115) 评论(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 阅读(141) 评论(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 阅读(118) 评论(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 阅读(118) 评论(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 阅读(127) 评论(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 阅读(126) 评论(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 阅读(89) 评论(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 阅读(117) 评论(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 阅读(126) 评论(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 阅读(114) 评论(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 阅读(135) 评论(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 阅读(112) 评论(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 阅读(149) 评论(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 阅读(176) 评论(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 阅读(102) 评论(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 阅读(136) 评论(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 阅读(132) 评论(0) 推荐(0) 编辑