摘要: 1 class Solution { 2 public: 3 int numTrees(int n) { 4 return dfs(1, n); 5 } 6 7 int dfs(int start, int end) { 8 if ... 阅读全文
posted @ 2014-03-24 23:53 卖程序的小歪 阅读(160) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: // verbose one vector insert(vector &intervals, Interval newInterval) { vector ret; int ns = newInterval.s... 阅读全文
posted @ 2014-03-24 18:50 卖程序的小歪 阅读(194) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: bool hasPathSum(TreeNode *root, int sum) { return dfs(root, 0, sum); } bool d... 阅读全文
posted @ 2014-03-24 16:06 卖程序的小歪 阅读(151) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: vector findSubstring(string S, vector &L) { vector res; unordered_map stat; unordered_map run; int len = S.size(); int num = L.size(); int per = 0; if (num == 0 || !(per = L[0].size())) return res; int part= num * per; if (part > len) return res; ... 阅读全文
posted @ 2014-03-22 14:41 卖程序的小歪 阅读(328) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int maxPathSum(TreeNode *root) { int s, m; dfs(root, s, m); return (m > s) ? m : s; } void d... 阅读全文
posted @ 2014-03-22 01:26 卖程序的小歪 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 引用可以简化原来使用指针的代码,至少看起来舒服点,不过今天发现个问题,先来看一段代码#include #include #include using namespace std;int main() { vector stack; stack.push_back(1); int& rx = stack[0]; int vx = stack[0]; int vy = rx; cout >::operator[] (0FC1276h) 00FC649F mov dword ptr [rx],eax i... 阅读全文
posted @ 2014-03-21 22:04 卖程序的小歪 阅读(246) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: vector preorderTraversal(TreeNode *root) { vector res; if (root == NULL) return ... 阅读全文
posted @ 2014-03-21 14:28 卖程序的小歪 阅读(134) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: vector inorderTraversal(TreeNode *root) { vector res; if (root == NULL) return res; vector > stack; ... 阅读全文
posted @ 2014-03-21 12:53 卖程序的小歪 阅读(218) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: vector twoSum(vector &numbers, int target) { vector ret; vector > nums; for (int i=0; i target) { ... 阅读全文
posted @ 2014-03-21 02:41 卖程序的小歪 阅读(202) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: int minimumTotal(vector > &triangle) { if (!triangle.size() || !triangle[0].size()) return 0; int row... 阅读全文
posted @ 2014-03-21 02:06 卖程序的小歪 阅读(126) 评论(0) 推荐(0) 编辑