
BFS
鸡蛋豆腐仙子
从本科开始讨厌了单片机 晶体管 编程 c++5-6年后,发现技术就是我的真爱,再重新选择一次,我还是会选择当程序员。我现在觉得自己什么都不会,可是还是相信会变成别人仰望的大神。
展开
-
minimum depth tree
class Solution {// 从叶子节点往上遍历,最终剩下的是结果public List findMinHeightTrees(int n, int[][] edges) {List res = new ArrayList<>();if (n == 1) {res.add(0);return res;}int[] degree = new int[n];Map<Integer, Set> map = new HashMap<>();for (i原创 2020-09-20 20:42:50 · 80 阅读 · 0 评论 -
【刷题】Leetcode559. Maximum Depth of N-ary Tree
DFS:/*// Definition for a Node.class Node { public int val; public List<Node> children; public Node() {} public Node(int _val,List<Node> _children) { val = _va...原创 2019-11-02 19:41:08 · 175 阅读 · 0 评论 -
【刷题】Leetcode 542. 01 Matrix
最近在刷搜索,DFS,BFS,backtracking的题。如果你是初学者,建议多看一些模版,然后一定动手写。我在上学的时候,对这些代码就只是看过,过了脑子,等自己写的时候,会发现很多问题。最近更新的代码DFS的一个套路,BFS的一个套路,然后等遇到具体问题具体分析。这道题莫名的看了半天solution,又取层数,又判断距离的,没想明白。最后直接写BFS也就过了。Given a matri...原创 2019-10-27 16:05:04 · 176 阅读 · 0 评论 -
【刷题】Leetcode 934. Shortest Bridge
睡醒解决了个bug。In a given 2D binary array A, there are two islands. (An island is a 4-directionally connected group of 1s not connected to any other 1s.)Now, we may change 0s to 1s so as to connect the ...原创 2019-11-06 21:12:50 · 174 阅读 · 0 评论 -
【刷题】Leetcode 127. Word Ladder
又写一道好老好老的题。第一次见到是。。。。四年前了吧,老得我都觉得自己没啥长进了。正能量正能量!Example 1:Input:beginWord = “hit”,endWord = “cog”,wordList = [“hot”,“dot”,“dog”,“lot”,“log”,“cog”]Output: 5Explanation: As one shortest transfor...原创 2019-11-02 13:36:31 · 153 阅读 · 0 评论 -
【刷题】Leetcode 101. Symmetric Tree
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:1/ 2 2/ \ / 3 4 4 3But the following [1,2,2,null,3,null,3] is not:1/ 2 2\ 3 3想到的是层遍历每一行,再判断是否是回文。Runtime: 1 ms, fas...原创 2019-11-01 08:52:27 · 116 阅读 · 0 评论