240
笔下虽有千言,胸中实无一策
摘要: 题解 Medium BFS 一个节点只计算一次,这一点要注意。 class Solution { public: bool validTree(int n, vector<vector<int>>& edges) { vector<unordered_set<int>> graph(n, unord 阅读全文
posted @ 2020-10-02 14:17 CasperWin 阅读(58) 评论(0) 推荐(0) 编辑
摘要: 题解 Easy | BFS 典型的求最大深度,用BFS。 class Solution { public: int maxDepth(Node* root) { if(!root) return 0; queue<Node*> q; q.push(root); int max_depth = 0; 阅读全文
posted @ 2020-10-02 13:37 CasperWin 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium BFS Deep Copy 的一个例子。 class Solution { public: Node* cloneGraph(Node* node) { if(!node) return nullptr; unordered_map<Node*, Node*> m; Node* 阅读全文
posted @ 2020-10-02 13:22 CasperWin 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 题解 Hard 难死了。 class Solution { public: vector<vector<string>> findLadders(string beginWord, string endWord, vector<string>& wordList) { unordered_set<s 阅读全文
posted @ 2020-10-02 12:55 CasperWin 阅读(62) 评论(0) 推荐(0) 编辑
摘要: 题解 Hard BFS class Solution { public: void cleanRoom(Robot& robot) { dfs(robot, 0, 0, 0); } void goback(Robot &r) { r.turnLeft(); r.turnLeft(); r.move( 阅读全文
posted @ 2020-10-02 11:37 CasperWin 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 题解 Medium 方法:BFS class Solution { public: int ladderLength(string beginWord, string endWord, vector<string>& wordList) { int steps = 0; unordered_set< 阅读全文
posted @ 2020-10-02 09:24 CasperWin 阅读(85) 评论(0) 推荐(0) 编辑
摘要: 题解 Easy 我倒是觉得不太容易,即使看了答案,也不确定这是令人信服的解法。直到看了动态图的讲解,所以还是画图更直观。 class Solution { public: int maxDistance(vector<vector<int>>& arrays) { int res = 0, min_ 阅读全文
posted @ 2020-10-02 07:53 CasperWin 阅读(125) 评论(0) 推荐(0) 编辑