摘要: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 vector generateTrees(int min, int max){13 if (min... 阅读全文
leetcode - Reorder List
2013-11-11 21:55 by 张汉生, 136 阅读, 0 推荐, 收藏, 编辑
摘要:1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 void reorderList(ListNode *head) {12 // IMPORTANT: Please reset any member data y... 阅读全文
leetcode - Validate Binary Search Tree
2013-11-10 11:14 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 #include 11 class Solution {12 public:13 bool isValid(TreeNode * node, int min, int max... 阅读全文
leetcode - Binary Tree Preorder Traversal
2013-11-10 10:58 by 张汉生, 149 阅读, 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 preOr(TreeNode * node, vector & rlt){13 if (n... 阅读全文
leetcode - Binary Tree Postorder Traversal
2013-11-10 10:46 by 张汉生, 192 阅读, 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 postTra(TreeNode * node, vector&rlt){13 if (n... 阅读全文
leetcode - Next Permutation
2013-11-10 10:33 by 张汉生, 185 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 void nextPermutation(vector &num) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 int n = num.size(); 6 if (n = 0; i--){10 if (num[i]num[i] && num[j]<min){21 min = nu... 阅读全文
leetcode - Subsets
2013-11-10 10:22 by 张汉生, 149 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 vector > subsets(vector &S) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 sort(S.begin(), S.end()); 6 int n = S.size(); 7 vector> rlt; 8 rlt.push_back(vector()); 9 int ... 阅读全文
leetcode - Permutations II
2013-11-10 10:20 by 张汉生, 132 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 vector > permuteUnique(vector &num) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 sort(num.begin(),num.end()); 7 vector> rlt; 8 rlt.push_... 阅读全文
leetcode - Valid Sudoku
2013-11-10 10:16 by 张汉生, 186 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 bool isValidSudoku(vector > &board) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 bool a[9][9]; 7 bool b[9][9]; 8 bool ct[9][9]; 9 ... 阅读全文
leetcode - Unique Paths II
2013-11-10 09:55 by 张汉生, 138 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 int uniquePathsWithObstacles(vector > &obstacleGrid) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 if (obstacleGrid.size() == 0 || obstacleGrid[0].size()... 阅读全文