摘要: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i... 阅读全文
posted @ 2015-03-24 17:30 keepshuatishuati 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int numTrees(int n) { 4 if (n dp(n+1, 0); 6 dp[0] = 1; 7 dp[1] = 1; 8 for (int i ... 阅读全文
posted @ 2015-03-24 17:27 keepshuatishuati 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 1 class TwoSum { 2 private: 3 unordered_map record; 4 public: 5 void add(int number) { 6 record[number]++; 7 } 8 9 bool find... 阅读全文
posted @ 2015-03-24 17:24 keepshuatishuati 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Here's the one I mentioned before. It comes as sorted array. 1 class Solution { 2 public: 3 vector twoSum(vector &numbers, int target) { 4 ... 阅读全文
posted @ 2015-03-24 17:21 keepshuatishuati 阅读(144) 评论(0) 推荐(0) 编辑
摘要: For two sum, we can sort the array and scan from two ends.Then space O(1), time O(nlogn)For here, it only accepts index. So we cant sort it as the ind... 阅读全文
posted @ 2015-03-24 17:19 keepshuatishuati 阅读(123) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int minimumTotal(vector > &triangle) { 4 int len = triangle.size(); 5 for (int i = len-2; i >= 0; ... 阅读全文
posted @ 2015-03-24 17:12 keepshuatishuati 阅读(115) 评论(0) 推荐(0) 编辑
摘要: Scanning from left to right and right to left.Find the max height of left and right. The minimum one will be most possible height for current state th... 阅读全文
posted @ 2015-03-24 17:06 keepshuatishuati 阅读(131) 评论(0) 推荐(0) 编辑
摘要: Clear with edge case. Such as L == 0, what to return. 1 class Solution { 2 public: 3 vector fullJustify(vector &words, int L) { 4 vector r... 阅读全文
posted @ 2015-03-24 17:00 keepshuatishuati 阅读(152) 评论(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-24 16:51 keepshuatishuati 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne... 阅读全文
posted @ 2015-03-24 16:49 keepshuatishuati 阅读(124) 评论(0) 推荐(0) 编辑
摘要: Scanning the border, if found an 'O', set it to 'Y'. Then do the BFS, get the 'Y' arounded 'O' to Y.Then the rest of 'O' will be set to the 'X'. 1 cla... 阅读全文
posted @ 2015-03-24 16:01 keepshuatishuati 阅读(129) 评论(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-24 15:45 keepshuatishuati 阅读(143) 评论(0) 推荐(0) 编辑
摘要: For this problem:1. use i = start; i dict) { 4 for (int i = 0; i 0) dict[s.substr(start + i*each, each)]--; 6 else return false;... 阅读全文
posted @ 2015-03-24 15:37 keepshuatishuati 阅读(109) 评论(0) 推荐(0) 编辑
摘要: Nothing fancy. Just skip the duplicated ones as num[i] == num[i-1] 1 class Solution { 2 public: 3 void getComb(vector > &result, vector &num, vect... 阅读全文
posted @ 2015-03-24 15:17 keepshuatishuati 阅读(103) 评论(0) 推荐(0) 编辑
摘要: Classical combination problem. 1 class Solution { 2 public: 3 void getComb(vector > &result, vector &num, vector current, int index, int len) { 4 ... 阅读全文
posted @ 2015-03-24 14:56 keepshuatishuati 阅读(101) 评论(0) 推荐(0) 编辑
摘要: Notes:INT_MAX's fabs is one less than INT_MIN's fabs.So when we use INT_MAX as the index. We need to use = '0') {11 if (result 0 ? IN... 阅读全文
posted @ 2015-03-24 14:52 keepshuatishuati 阅读(118) 评论(0) 推荐(0) 编辑
摘要: Newton method, need enought accuracy of tolerance to handle edge case INT_MAX and INT_MIN: 1 class Solution { 2 public: 3 int sqrt(int x) { 4 ... 阅读全文
posted @ 2015-03-24 14:46 keepshuatishuati 阅读(131) 评论(0) 推荐(0) 编辑
摘要: Do not forget to assign size value of matrix. This is very important!!!! 1 class Solution { 2 public: 3 vector > generateMatrix(int n) { 4 ... 阅读全文
posted @ 2015-03-24 14:39 keepshuatishuati 阅读(115) 评论(0) 推荐(0) 编辑
摘要: When finally check the middle line, it is checking whether the min(n, m) is odd or even number. 1 class Solution { 2 public: 3 vector spiralOrder(... 阅读全文
posted @ 2015-03-24 14:34 keepshuatishuati 阅读(122) 评论(0) 推荐(0) 编辑
摘要: Use merge sort. Recursively call the function: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNod... 阅读全文
posted @ 2015-03-24 14:24 keepshuatishuati 阅读(126) 评论(0) 推荐(0) 编辑