摘要:
``` class Solution { public: int sumNumbers(TreeNode* root) { return sumNumbersDFS(root, 0); } int sumNumbersDFS(TreeNode* root, int sum) { if (!root) return 0; sum... 阅读全文
posted @ 2019-04-09 16:15
JohnRed
阅读(65)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int longestConsecutive(vector& nums) { int res = 0; unordered_set s(nums.begin(), nums.end()); for (int val : nums) { if (!s.count(... 阅读全文
posted @ 2019-04-09 16:05
JohnRed
阅读(86)
评论(0)
推荐(0)
摘要:
``` class Solution { public: typedef unordered_set::iterator HashIter; vector findLadders(string start, string end, unordered_set &dict) { // Note: Th 阅读全文
posted @ 2019-04-09 15:35
JohnRed
阅读(76)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int ladderLength(string start, string end, unordered_set &dict) { // IMPORTANT: Please reset any member data you declared 阅读全文
posted @ 2019-04-09 15:35
JohnRed
阅读(172)
评论(0)
推荐(0)
摘要:
``` class Solution { public: bool isPalindrome(string s) { int left = 0, right = s.size() 1 ; while (left = 'a' && ch = 'A' && ch = '0' && ch 阅读全文
posted @ 2019-04-09 15:32
JohnRed
阅读(107)
评论(0)
推荐(0)
摘要:
```
class Solution {
public: int maxPathSum(TreeNode* root) { int res = INT_MIN; helper(root, res); return res; } int helper(TreeNode* node, int& res) { if ... 阅读全文
posted @ 2019-04-09 15:30
JohnRed
阅读(86)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int maxProfit(vector &prices) { if (prices.empty()) return 0; int n = prices.size(), g[n][3] = {0}, l[n][3] = {0}; for (i 阅读全文
posted @ 2019-04-09 15:28
JohnRed
阅读(65)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int maxProfit(vector& prices) { int res = 0, n = prices.size(); for (int i = 0; i 阅读全文
posted @ 2019-04-09 15:26
JohnRed
阅读(94)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int maxProfit(vector& prices) { int n = prices.size(); if (n==0){ return 0; } int res = 0; int mmin = prices[0]; for (int 阅读全文
posted @ 2019-04-09 15:25
JohnRed
阅读(77)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int minimumTotal(vector & triangle) { vector dp(triangle.back()); for (int i = (int)triangle.size() 2; i = 0; i) { for (i 阅读全文
posted @ 2019-04-09 15:24
JohnRed
阅读(77)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector getRow(int rowIndex) { vector res(rowIndex + 1); res[0] = 1; for (int i = 1; i = 1; --j) { res[j] += res[j - 1]; ... 阅读全文
posted @ 2019-04-09 15:22
JohnRed
阅读(52)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector generate(int numRows) { vector res(numRows, vector()); for (int i = 0; i 阅读全文
posted @ 2019-04-09 15:21
JohnRed
阅读(87)
评论(0)
推荐(0)
摘要:
``` class Solution { public: Node* connect(Node* root) { if (!root) return NULL; Node *p = root->next; while (p) { if (p->left) { p = p->left; ... 阅读全文
posted @ 2019-04-09 15:20
JohnRed
阅读(87)
评论(0)
推荐(0)
摘要:
``` class Solution { public: Node* connect(Node* root) { if (!root) return NULL; if (root->left) root->left->next = root->right; if (root->right) root->right->next = root->... 阅读全文
posted @ 2019-04-09 15:18
JohnRed
阅读(69)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int numDistinct(string S, string T) { int dp[T.size() + 1][S.size() + 1]; for (int i = 0; i 阅读全文
posted @ 2019-04-09 15:15
JohnRed
阅读(93)
评论(0)
推荐(0)
摘要:
``` // Recursion class Solution { public: void flatten(TreeNode *root) { if (!root) return; if (root->left) flatten(root->left); if (root->right) flatten(root->right); ... 阅读全文
posted @ 2019-04-09 15:14
JohnRed
阅读(70)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector > pathSum(TreeNode *root, int sum) { vector> res; vector out; helper(root, sum, out, res); return res; } void helper(Tre... 阅读全文
posted @ 2019-04-09 15:11
JohnRed
阅读(75)
评论(0)
推荐(0)
摘要:
``` class Solution { public: bool hasPathSum(TreeNode* root, int sum) { if (!root) return false; if (!root->left && !root->right && root->val == sum ) return true; return h... 阅读全文
posted @ 2019-04-09 15:10
JohnRed
阅读(84)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int minDepth(TreeNode* root) { if (!root) return 0; if (!root->left) return 1 + minDepth(root->right); if (!root->right) return 1 + minDepth(ro... 阅读全文
posted @ 2019-04-09 15:04
JohnRed
阅读(74)
评论(0)
推荐(0)
摘要:
```
class Solution {
public: bool isBalanced(TreeNode *root) { if (checkDepth(root) == -1) return false; else return true; } int checkDepth(TreeNode *root) { if... 阅读全文
posted @ 2019-04-09 15:03
JohnRed
阅读(105)
评论(0)
推荐(0)

浙公网安备 33010602011771号