240
笔下虽有千言,胸中实无一策
摘要: 题解 Easy | DFS class Solution { public: vector<string> binaryTreePaths(TreeNode* root) { vector<string> paths; dfs(root, "", paths); return paths; } vo 阅读全文
posted @ 2020-09-30 14:53 CasperWin 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium | DFS class Solution { public: vector<vector<int>> pathSum(TreeNode* root, int sum) { vector<vector<int>> paths; vector<int> path; dfs(root, 阅读全文
posted @ 2020-09-30 14:44 CasperWin 阅读(62) 评论(0) 推荐(0) 编辑
摘要: 题解 Hard 方法一:DFS + Memoization class Solution { public: int longestIncreasingPath(vector<vector<int>>& matrix) { if(matrix.empty()) return 0; m = matri 阅读全文
posted @ 2020-09-30 14:27 CasperWin 阅读(81) 评论(0) 推荐(0) 编辑
摘要: 题解 Easy 方法一:Greedy 贪心算法 class Solution { public: string longestWord(vector<string>& words) { string res; unordered_set<string> s; sort(words.begin(), 阅读全文
posted @ 2020-09-30 13:26 CasperWin 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 题解 Easy | Tree, DFS class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(!p && !q) return true; if(!p || !q) return false; if(p->va 阅读全文
posted @ 2020-09-30 12:25 CasperWin 阅读(72) 评论(0) 推荐(0) 编辑
摘要: 题解 Easy | Tree, DFS class Solution { public: bool hasPathSum(TreeNode* root, int sum) { if(!root) return false; if(!root->left && !root->right) return 阅读全文
posted @ 2020-09-30 12:04 CasperWin 阅读(53) 评论(0) 推荐(0) 编辑