240
笔下虽有千言,胸中实无一策
上一页 1 2 3 4 5 6 7 ··· 17 下一页
摘要: 题解 Hard 方法:Trie struct TrieNode { vector<int> indexes; vector<TrieNode*> next; TrieNode() : next(26, nullptr) { } }; class Solution { public: vector<v 阅读全文
posted @ 2020-10-01 07:47 CasperWin 阅读(95) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium Heap (Priority Queue) 难点是自己写comparator。 class comparator { public: bool operator() (const pair<string, int>& a, const pair<string, int>& b) 阅读全文
posted @ 2020-10-01 06:50 CasperWin 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium Topological Sort class Solution { public: vector<int> findOrder(int numCourses, vector<vector<int>>& prerequisites) { vector<vector<int>> gr 阅读全文
posted @ 2020-10-01 05:52 CasperWin 阅读(79) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium 方法:Topological Sort class Solution { public: bool canFinish(int numCourses, vector<vector<int>>& prerequisites) { vector<vector<int>> graph( 阅读全文
posted @ 2020-10-01 05:42 CasperWin 阅读(76) 评论(0) 推荐(0) 编辑
摘要: 题解 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 阅读(60) 评论(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 阅读(80) 评论(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) 编辑
摘要: 题解 Easy | Hashmap class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) { unordered_map<int, int> m; for(int i = 0; i < number 阅读全文
posted @ 2020-09-29 13:31 CasperWin 阅读(46) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium | Backtracking class Solution { public: vector<vector<int>> subsetsWithDup(vector<int>& nums) { sort(nums.begin(), nums.end()); vector<vecto 阅读全文
posted @ 2020-09-29 12:58 CasperWin 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium | Backtracking class Solution { public: vector<vector<int>> subsets(vector<int>& nums) { sort(nums.begin(), nums.end()); vector<vector<int>> 阅读全文
posted @ 2020-09-29 12:55 CasperWin 阅读(67) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium | Backtracking class Solution { public: int getMaximumGold(vector<vector<int>>& grid) { int ret = 0; for(int i = 0; i < grid.size(); i++) { 阅读全文
posted @ 2020-09-29 12:37 CasperWin 阅读(74) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium | Backtracking class Solution { public: vector<vector<int>> combinationSum3(int k, int n) { vector<vector<int>> sols; vector<int> sol; helpe 阅读全文
posted @ 2020-09-29 12:15 CasperWin 阅读(81) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 17 下一页