摘要:
```
class Solution {
public: void recoverTree(TreeNode *root) { TreeNode *cur=root,*pre=nullptr; TreeNode *first=nullptr,*second=nullptr,*parent=nullptr; while(cur) ... 阅读全文
posted @ 2019-04-09 14:30
JohnRed
阅读(75)
评论(0)
推荐(0)
摘要:
``` // Recursion without inorder traversal class Solution { public: bool isValidBST(TreeNode* root) { return isValidBST(root, LONG_MIN, LONG_MAX); } bool isValidBST(TreeNode* root,... 阅读全文
posted @ 2019-04-09 14:25
JohnRed
阅读(75)
评论(0)
推荐(0)
摘要:
``` class Solution { public: bool isInterleave(string s1, string s2, string s3) { int m = s1.size(); int n = s2.size(); if(m+n != s3.size()) return fa 阅读全文
posted @ 2019-04-09 14:20
JohnRed
阅读(87)
评论(0)
推荐(0)
摘要:
```class Solution { public: int numTrees(int n) { vector dp(n + 1, 0); dp[0] = 1; dp[1] = 1; for (int i = 2; i 阅读全文
posted @ 2019-04-09 14:17
JohnRed
阅读(64)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector generateTrees(int n) { if (n == 0) return {}; return *generateTreesDFS(1, n); } vector *generateTreesDFS(int start, int end) { v... 阅读全文
posted @ 2019-04-09 14:16
JohnRed
阅读(68)
评论(0)
推荐(0)
摘要:
``` // Recursion class Solution { public: vector inorderTraversal(TreeNode *root) { vector res; inorder(root, res); return res; } void inorder(TreeNode *root, vecto... 阅读全文
posted @ 2019-04-09 14:13
JohnRed
阅读(70)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int numDecodings(string s) { if (s.empty() || (s.size() 1 && s[0] == '0')) return 0; vector dp(s.size() + 1, 0); dp[0] = 阅读全文
posted @ 2019-04-09 12:10
JohnRed
阅读(86)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector subsetsWithDup(vector &S) { if (S.empty()) return {}; vector res(1); sort(S.begin(), S.end()); int size = 1, last 阅读全文
posted @ 2019-04-09 12:08
JohnRed
阅读(84)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector grayCode(int n) { vector result; for(int i=0;i>1); } return result; } }; ``` 阅读全文
posted @ 2019-04-09 12:07
JohnRed
阅读(89)
评论(0)
推荐(0)
摘要:
``` class Solution { public: void merge(vector& nums1, int m, vector& nums2, int n) { int i = m - 1, j = n - 1, k = m + n - 1; while (i >= 0 && j >= 0) { if (nums1[i] >... 阅读全文
posted @ 2019-04-09 12:04
JohnRed
阅读(62)
评论(0)
推荐(0)

浙公网安备 33010602011771号