代码改变世界

leetcode - Subsets II

2013-11-06 11:22 by 张汉生, 193 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 vector > subsetsWithDup(vector &S) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 sort(S.begin(), S.end()); 7 int n = S.size(); 8 vector> ... 阅读全文

leetcode - Search for a Range

2013-11-06 10:45 by 张汉生, 132 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 vector searchRange(int A[], int n, int target) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 if (n(2,-1); 8 int l = 0, r = n-1; 9 int m;1... 阅读全文

leetcode - Path Sum II

2013-11-06 10:19 by 张汉生, 146 阅读, 0 推荐, 收藏, 编辑
摘要:1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */10 class Solution {11 public:12 void getResult (TreeNode * node, vector> & rlt, int target... 阅读全文

leetcode - Trapping Rain Water

2013-11-06 09:50 by 张汉生, 170 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 int trap(int A[], int n) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 int * lr = new int [n]; 7 int last = 0; 8 for (int i=0; i=0; i--){... 阅读全文

leetcode - Sum Root to Leaf Numbers

2013-11-06 09:25 by 张汉生, 141 阅读, 0 推荐, 收藏, 编辑
摘要:1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */10 class Solution {11 public:12 void sumNumbers(TreeNode *node, int &totalSum, int curSum)... 阅读全文

leetcode - Valid Parentheses

2013-11-05 23:17 by 张汉生, 144 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 bool isValid(string s) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 stack sc; 7 int len = s.length(); 8 for (int i=0; i<len; i++){ 9 ... 阅读全文

leetcode - Minimum Depth of Binary Tree

2013-11-05 22:56 by 张汉生, 125 阅读, 0 推荐, 收藏, 编辑
摘要:1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */10 class Solution {11 public:12 void minDepth(TreeNode * node, int & minDep, int curDepth)... 阅读全文

leetcode - Search in Rotated Sorted Array II

2013-11-05 22:48 by 张汉生, 172 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 bool search(int A[], int n, int target) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 if (n<=0) // cannot decide which side target should be, so O(n) 7 ... 阅读全文

leetcode - Search in Rotated Sorted Array

2013-11-05 22:35 by 张汉生, 154 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 int search(int A[], int n, int target) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 if (ntarget){19 if (A[right]>target){20 ... 阅读全文

leetcode - Palindrome Number

2013-11-02 21:49 by 张汉生, 191 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 int tenPow(int a){ 4 int rlt = 1; 5 while (a-- > 0){ 6 rlt *= 10; 7 } 8 return rlt; 9 }10 bool isPalindrome(int x) {11 // IMPORTANT: Please reset any member data you declared, as12 // the same Sol... 阅读全文
上一页 1 2 3 4 5 6 7 8 9 10 ··· 16 下一页