Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/leetcode/editor/cn/all.json
This commit is contained in:
huangge1199@hotmail.com 2021-08-02 18:18:57 +08:00
commit 373f267c87
22 changed files with 1579 additions and 1 deletions

View File

@ -0,0 +1,65 @@
package com.code.leet.entiy;
import lombok.Data;
/**
* Created with IntelliJ IDEA.
*
* @author: 轩辕龙儿
* @date: 2021/7/30 14:06
* @Description: No Description
*/
@Data
public class TwoArray {
int[][] arr;
public TwoArray(String str, boolean bl) {
if (bl) {
getSquArr(str);
} else {
getArr(str);
}
}
private void getSquArr(String str) {
int xLength = str.length() - str.replace("[", "").length() - 1;
int yLength = (str.length() - str.replace(",", "").length() - xLength + 1) / xLength + 1;
arr = new int[xLength][yLength];
int xIndex = 0;
int yIndex = 0;
String iStr = "";
for (char ch : str.toCharArray()) {
if (Character.isDigit(ch)) {
iStr += ch;
} else {
if (!iStr.equals("")) {
arr[xIndex][yIndex] = Integer.parseInt(iStr);
iStr = "";
yIndex += 1;
if (yIndex == yLength) {
yIndex = 0;
xIndex += 1;
}
}
}
}
}
private void getArr(String str) {
str = str.substring(2, str.length() - 2);
String[] strings = str.split("],\\[");
arr = new int[strings.length][];
for (int i = 0; i < strings.length; i++) {
if("".equals(strings[i])){
arr[i] = new int[0];
continue;
}
String[] strs = strings[i].split(",");
arr[i] = new int[strs.length];
for (int j = 0; j < strs.length; j++) {
arr[i][j] = Integer.parseInt(strs[j]);
}
}
}
}

View File

@ -0,0 +1,89 @@
//给你一个二叉树请你返回其按 层序遍历 得到的节点值 即逐层地从左到右访问所有节点
//
//
//
// 示例
//二叉树[3,9,20,null,null,15,7],
//
//
// 3
// / \
// 9 20
// / \
// 15 7
//
//
// 返回其层序遍历结果
//
//
//[
// [3],
// [9,20],
// [15,7]
//]
//
// Related Topics 广度优先搜索 二叉树
// 👍 945 👎 0
package leetcode.editor.cn;
import com.code.leet.entiy.TreeNode;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
//102:二叉树的层序遍历
public class BinaryTreeLevelOrderTraversal {
public static void main(String[] args) {
//测试代码
Solution solution = new BinaryTreeLevelOrderTraversal().new Solution();
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<List<Integer>> levelOrder(TreeNode root) {
if (root == null) {
return new ArrayList<>();
}
Queue<TreeNode> queue = new LinkedList<>();
List<List<Integer>> result = new ArrayList<>();
queue.add(root);
while (!queue.isEmpty()) {
int size = queue.size();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < size; i++) {
TreeNode temp = queue.poll();
list.add(temp.val);
if (temp.left != null) {
queue.add(temp.left);
}
if (temp.right != null) {
queue.add(temp.right);
}
}
result.add(list);
}
return result;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,25 @@
<p>给你一个二叉树,请你返回其按 <strong>层序遍历</strong> 得到的节点值。 (即逐层地,从左到右访问所有节点)。</p>
<p> </p>
<p><strong>示例:</strong><br />
二叉树:<code>[3,9,20,null,null,15,7]</code>,</p>
<pre>
3
/ \
9 20
/ \
15 7
</pre>
<p>返回其层序遍历结果:</p>
<pre>
[
[3],
[9,20],
[15,7]
]
</pre>
<div><div>Related Topics</div><div><li></li><li>广度优先搜索</li><li>二叉树</li></div></div>\n<div><li>👍 945</li><li>👎 0</li></div>

View File

@ -0,0 +1,107 @@
//给定一个无重复元素的正整数数组 candidates 和一个正整数 target 找出 candidates 中所有可以使数字和为目标数 target
//唯一组合
//
// candidates 中的数字可以无限制重复被选取如果至少一个所选数字数量不同则两种组合是唯一的
//
// 对于给定的输入保证和为 target 的唯一组合数少于 150
//
//
//
// 示例 1
//
//
//输入: candidates = [2,3,6,7], target = 7
//输出: [[7],[2,2,3]]
//
//
// 示例 2
//
//
//输入: candidates = [2,3,5], target = 8
//输出: [[2,2,2,2],[2,3,3],[3,5]]
//
// 示例 3
//
//
//输入: candidates = [2], target = 1
//输出: []
//
//
// 示例 4
//
//
//输入: candidates = [1], target = 1
//输出: [[1]]
//
//
// 示例 5
//
//
//输入: candidates = [1], target = 2
//输出: [[1,1]]
//
//
//
//
// 提示
//
//
// 1 <= candidates.length <= 30
// 1 <= candidates[i] <= 200
// candidate 中的每个元素都是独一无二的
// 1 <= target <= 500
//
// Related Topics 数组 回溯
// 👍 1458 👎 0
package leetcode.editor.cn;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
//39:组合总和
public class CombinationSum {
public static void main(String[] args) {
//测试代码
Solution solution = new CombinationSum().new Solution();
solution.combinationSum(new int[]{2, 3, 6, 7}, 7);
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
List<List<Integer>> list = new ArrayList<>();
boolean bl = false;
public List<List<Integer>> combinationSum(int[] candidates, int target) {
Arrays.sort(candidates);
backtrack(candidates, 0, new ArrayList<>(), 0, target);
return list;
}
private void backtrack(int[] candidates, int index, List<Integer> use, int sum, int target) {
if (sum == target) {
list.add(new ArrayList<>(use));
bl = true;
return;
}
if (sum > target) {
bl = true;
return;
}
for (int i = index; i < candidates.length; i++) {
use.add(candidates[i]);
backtrack(candidates, i, use, sum + candidates[i], target);
use.remove(use.size() - 1);
if(bl){
break;
}
}
bl = false;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,53 @@
<p>给定一个<strong>无重复元素</strong>的正整数数组 <code>candidates</code> 和一个正整数 <code>target</code> ,找出 <code>candidates</code> 中所有可以使数字和为目标数 <code>target</code> 的唯一组合。</p>
<p><code>candidates</code> 中的数字可以无限制重复被选取。如果至少一个所选数字数量不同,则两种组合是唯一的。 </p>
<p>对于给定的输入,保证和为 <code>target</code> 的唯一组合数少于 <code>150</code> 个。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入: </strong>candidates = <code>[2,3,6,7], </code>target = <code>7</code>
<strong>输出: </strong>[[7],[2,2,3]]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入: </strong>candidates = [2,3,5]<code>, </code>target = 8
<strong>输出: </strong>[[2,2,2,2],[2,3,3],[3,5]]</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入: </strong>candidates = <code>[2], </code>target = 1
<strong>输出: </strong>[]
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入: </strong>candidates = <code>[1], </code>target = <code>1</code>
<strong>输出: </strong>[[1]]
</pre>
<p><strong>示例 5</strong></p>
<pre>
<strong>输入: </strong>candidates = <code>[1], </code>target = <code>2</code>
<strong>输出: </strong>[[1,1]]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= candidates.length <= 30</code></li>
<li><code>1 <= candidates[i] <= 200</code></li>
<li><code>candidate</code> 中的每个元素都是独一无二的。</li>
<li><code>1 <= target <= 500</code></li>
</ul>
<div><div>Related Topics</div><div><li>数组</li><li>回溯</li></div></div>\n<div><li>👍 1458</li><li>👎 0</li></div>

View File

@ -0,0 +1,86 @@
//给你一个字符串 columnTitle 表示 Excel 表格中的列名称返回该列名称对应的列序号
//
//
//
// 例如
//
//
// A -> 1
// B -> 2
// C -> 3
// ...
// Z -> 26
// AA -> 27
// AB -> 28
// ...
//
//
//
//
// 示例 1:
//
//
//输入: columnTitle = "A"
//输出: 1
//
//
// 示例 2:
//
//
//输入: columnTitle = "AB"
//输出: 28
//
//
// 示例 3:
//
//
//输入: columnTitle = "ZY"
//输出: 701
//
// 示例 4:
//
//
//输入: columnTitle = "FXSHRXW"
//输出: 2147483647
//
//
//
//
// 提示
//
//
// 1 <= columnTitle.length <= 7
// columnTitle 仅由大写英文组成
// columnTitle 在范围 ["A", "FXSHRXW"]
//
// Related Topics 数学 字符串
// 👍 260 👎 0
package leetcode.editor.cn;
//171:Excel 表列序号
public class ExcelSheetColumnNumber {
public static void main(String[] args) {
//测试代码
Solution solution = new ExcelSheetColumnNumber().new Solution();
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public int titleToNumber(String columnTitle) {
char[] chs = columnTitle.toCharArray();
int result = 0;
int size = chs.length - 1;
int mul = 1;
for (int i = 0; i <= size; i++) {
int num = chs[size - i] - 'A' + 1;
result += num * mul;
mul *= 26;
}
return result;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,56 @@
<p>给你一个字符串&nbsp;<code>columnTitle</code> ,表示 Excel 表格中的列名称。返回该列名称对应的列序号。</p>
<p>&nbsp;</p>
<p>例如,</p>
<pre>
A -&gt; 1
B -&gt; 2
C -&gt; 3
...
Z -&gt; 26
AA -&gt; 27
AB -&gt; 28
...
</pre>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong> columnTitle = "A"
<strong>输出:</strong> 1
</pre>
<p><strong>示例&nbsp;2:</strong></p>
<pre>
<strong>输入: </strong>columnTitle = "AB"
<strong>输出:</strong> 28
</pre>
<p><strong>示例&nbsp;3:</strong></p>
<pre>
<strong>输入: </strong>columnTitle = "ZY"
<strong>输出:</strong> 701</pre>
<p><strong>示例 4:</strong></p>
<pre>
<strong>输入: </strong>columnTitle = "FXSHRXW"
<strong>输出: </strong>2147483647
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= columnTitle.length &lt;= 7</code></li>
<li><code>columnTitle</code> 仅由大写英文组成</li>
<li><code>columnTitle</code> 在范围 <code>["A", "FXSHRXW"]</code></li>
</ul>
<div><div>Related Topics</div><div><li>数学</li><li>字符串</li></div></div>\n<div><li>👍 260</li><li>👎 0</li></div>

View File

@ -0,0 +1,102 @@
//中位数是有序列表中间的数如果列表长度是偶数中位数则是中间两个数的平均值
//
// 例如
//
// [2,3,4] 的中位数是 3
//
// [2,3] 的中位数是 (2 + 3) / 2 = 2.5
//
// 设计一个支持以下两种操作的数据结构
//
//
// void addNum(int num) - 从数据流中添加一个整数到数据结构中
// double findMedian() - 返回目前所有元素的中位数
//
//
// 示例
//
// addNum(1)
//addNum(2)
//findMedian() -> 1.5
//addNum(3)
//findMedian() -> 2
//
// 进阶:
//
//
// 如果数据流中所有整数都在 0 100 范围内你将如何优化你的算法
// 如果数据流中 99% 的整数都在 0 100 范围内你将如何优化你的算法
//
// Related Topics 设计 双指针 数据流 排序 优先队列
// 👍 449 👎 0
package leetcode.editor.cn;
import java.util.*;
//295:数据流的中位数
public class FindMedianFromDataStream {
public static void main(String[] args) {
//测试代码
// Solution solution = new FindMedianFromDataStream().new Solution();
MedianFinder medianFinder = null;
List<String> list1 = Arrays.asList("MedianFinder", "addNum", "findMedian", "addNum", "findMedian", "addNum", "findMedian", "addNum", "findMedian", "addNum", "findMedian");
List<Integer> list2 = Arrays.asList(null, -1, null, -2, null, -3, null, -4, null, -5, null);
for (int i = 0; i < list1.size(); i++) {
if ("MedianFinder".equals(list1.get(i))) {
medianFinder = new FindMedianFromDataStream().new MedianFinder();
} else if ("addNum".equals(list1.get(i))) {
medianFinder.addNum(list2.get(i));
} else {
System.out.println(medianFinder.findMedian());
}
}
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class MedianFinder {
/**
* 当前大顶堆和小顶堆的元素个数之和
*/
private int count;
private PriorityQueue<Integer> max;
private PriorityQueue<Integer> minheap;
/**
* initialize your data structure here.
*/
public MedianFinder() {
count = 0;
max = new PriorityQueue<>((x, y) -> y - x);
minheap = new PriorityQueue<>();
}
public void addNum(int num) {
count += 1;
max.offer(num);
minheap.add(max.poll());
if ((count & 1) != 0) {
max.add(minheap.poll());
}
}
public double findMedian() {
if ((count & 1) == 0) {
return (double) (max.peek() + minheap.peek()) / 2;
} else {
return (double) max.peek();
}
}
}
/**
* Your MedianFinder object will be instantiated and called as such:
* MedianFinder obj = new MedianFinder();
* obj.addNum(num);
* double param_2 = obj.findMedian();
*/
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,30 @@
<p>中位数是有序列表中间的数。如果列表长度是偶数,中位数则是中间两个数的平均值。</p>
<p>例如,</p>
<p>[2,3,4]&nbsp;的中位数是 3</p>
<p>[2,3] 的中位数是 (2 + 3) / 2 = 2.5</p>
<p>设计一个支持以下两种操作的数据结构:</p>
<ul>
<li>void addNum(int num) - 从数据流中添加一个整数到数据结构中。</li>
<li>double findMedian() - 返回目前所有元素的中位数。</li>
</ul>
<p><strong>示例:</strong></p>
<pre>addNum(1)
addNum(2)
findMedian() -&gt; 1.5
addNum(3)
findMedian() -&gt; 2</pre>
<p><strong>进阶:</strong></p>
<ol>
<li>如果数据流中所有整数都在 0 到 100 范围内,你将如何优化你的算法?</li>
<li>如果数据流中 99% 的整数都在 0 到 100 范围内,你将如何优化你的算法?</li>
</ol>
<div><div>Related Topics</div><div><li>设计</li><li>双指针</li><li>数据流</li><li>排序</li><li>堆(优先队列)</li></div></div>\n<div><li>👍 449</li><li>👎 0</li></div>

View File

@ -0,0 +1,104 @@
//存在一个 无向图 图中有 n 个节点其中每个节点都有一个介于 0 n - 1 之间的唯一编号给你一个二维数组 graph 其中 graph[u]
// 是一个节点数组由节点 u 的邻接节点组成形式上对于 graph[u] 中的每个 v 都存在一条位于节点 u 和节点 v 之间的无向边该无向图同时具有
//以下属性
//
// 不存在自环graph[u] 不包含 u
// 不存在平行边graph[u] 不包含重复值
// 如果 v graph[u] 那么 u 也应该在 graph[v] 该图是无向图
// 这个图可能不是连通图也就是说两个节点 u v 之间可能不存在一条连通彼此的路径
//
//
// 二分图 定义如果能将一个图的节点集合分割成两个独立的子集 A B 并使图中的每一条边的两个节点一个来自 A 集合一个来自 B 集合就将这个图称
// 二分图
//
// 如果图是二分图返回 true 否则返回 false
//
//
//
// 示例 1
//
//
//输入graph = [[1,2,3],[0,2],[0,1,3],[0,2]]
//输出false
//解释不能将节点分割成两个独立的子集以使每条边都连通一个子集中的一个节点与另一个子集中的一个节点
//
// 示例 2
//
//
//输入graph = [[1,3],[0,2],[1,3],[0,2]]
//输出true
//解释可以将节点分成两组: {0, 2} {1, 3}
//
//
//
// 提示
//
//
// graph.length == n
// 1 <= n <= 100
// 0 <= graph[u].length < n
// 0 <= graph[u][i] <= n - 1
// graph[u] 不会包含 u
// graph[u] 的所有值 互不相同
// 如果 graph[u] 包含 v那么 graph[v] 也会包含 u
//
// Related Topics 深度优先搜索 广度优先搜索 并查集
// 👍 283 👎 0
package leetcode.editor.cn;
import com.code.leet.entiy.TwoArray;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
//785:判断二分图
public class IsGraphBipartite {
public static void main(String[] args) {
//测试代码
Solution solution = new IsGraphBipartite().new Solution();
// TwoArray twoArray = new TwoArray("[[1,3],[0,2],[1,3],[0,2]]");
System.out.println("-------------------------------");
TwoArray twoArray = new TwoArray("[[],[2,4,6],[1,4,8,9],[7,8],[1,2,8,9],[6,9],[1,5,7,8,9],[3,6,9],[2,3,4,6,9],[2,4,5,6,7,8]]",false);
System.out.println(solution.isBipartite(twoArray.getArr()));
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public boolean isBipartite(int[][] graph) {
int max = graph.length;
int[] use = new int[max];
Arrays.fill(use, -1);
for (int k = 0; k < graph.length; k++) {
if (use[k] > -1) {
continue;
}
use[k] = 0;
Queue<Integer> queue = new LinkedList<>();
queue.add(k);
while (!queue.isEmpty()) {
int size = queue.size();
for (int j = 0; j < size; j++) {
int num = queue.poll();
int cur = 1 - use[num];
for (int i = 0; i < graph[num].length; i++) {
int curNum = graph[num][i];
if (use[curNum] == use[num]) {
return false;
}
if (use[curNum] == -1) {
use[curNum] = cur;
queue.add(curNum);
}
}
}
}
}
return true;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,42 @@
存在一个 <strong>无向图</strong> ,图中有 <code>n</code> 个节点。其中每个节点都有一个介于 <code>0</code><code>n - 1</code> 之间的唯一编号。给你一个二维数组 <code>graph</code> ,其中 <code>graph[u]</code> 是一个节点数组,由节点 <code>u</code> 的邻接节点组成。形式上,对于 <code>graph[u]</code> 中的每个 <code>v</code> ,都存在一条位于节点 <code>u</code> 和节点 <code>v</code> 之间的无向边。该无向图同时具有以下属性:
<ul>
<li>不存在自环(<code>graph[u]</code> 不包含 <code>u</code>)。</li>
<li>不存在平行边(<code>graph[u]</code> 不包含重复值)。</li>
<li>如果 <code>v</code><code>graph[u]</code> 内,那么 <code>u</code> 也应该在 <code>graph[v]</code> 内(该图是无向图)</li>
<li>这个图可能不是连通图,也就是说两个节点 <code>u</code><code>v</code> 之间可能不存在一条连通彼此的路径。</li>
</ul>
<p><strong>二分图</strong> 定义:如果能将一个图的节点集合分割成两个独立的子集 <code>A</code><code>B</code> ,并使图中的每一条边的两个节点一个来自 <code>A</code> 集合,一个来自 <code>B</code> 集合,就将这个图称为 <strong>二分图</strong></p>
<p>如果图是二分图,返回 <code>true</code><em> </em>;否则,返回 <code>false</code></p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/21/bi2.jpg" style="width: 222px; height: 222px;" />
<pre>
<strong>输入:</strong>graph = [[1,2,3],[0,2],[0,1,3],[0,2]]
<strong>输出:</strong>false
<strong>解释:</strong><code>不能将节点分割成两个独立的子集,</code>以使每条边都连通一个子集中的一个节点与另一个子集中的一个节点。</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/10/21/bi1.jpg" style="width: 222px; height: 222px;" />
<pre>
<strong>输入:</strong>graph = [[1,3],[0,2],[1,3],[0,2]]
<strong>输出:</strong>true
<strong>解释:</strong><code>可以将节点分成两组: {0, 2} 和 {1, 3} 。</code></pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>graph.length == n</code></li>
<li><code>1 <= n <= 100</code></li>
<li><code>0 <= graph[u].length < n</code></li>
<li><code>0 <= graph[u][i] <= n - 1</code></li>
<li><code>graph[u]</code> 不会包含 <code>u</code></li>
<li><code>graph[u]</code> 的所有值 <strong>互不相同</strong></li>
<li>如果 <code>graph[u]</code> 包含 <code>v</code>,那么 <code>graph[v]</code> 也会包含 <code>u</code></li>
</ul>
<div><div>Related Topics</div><div><li>深度优先搜索</li><li>广度优先搜索</li><li>并查集</li><li></li></div></div>\n<div><li>👍 283</li><li>👎 0</li></div>

View File

@ -0,0 +1,123 @@
//n 皇后问题 研究的是如何将 n 个皇后放置在 n×n 的棋盘上并且使皇后彼此之间不能相互攻击
//
// 给你一个整数 n 返回所有不同的 n 皇后问题 的解决方案
//
//
//
// 每一种解法包含一个不同的 n 皇后问题 的棋子放置方案该方案中 'Q' '.' 分别代表了皇后和空位
//
//
//
// 示例 1
//
//
//输入n = 4
//输出[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
//解释如上图所示4 皇后问题存在两个不同的解法
//
//
// 示例 2
//
//
//输入n = 1
//输出[["Q"]]
//
//
//
//
// 提示
//
//
// 1 <= n <= 9
// 皇后彼此不能相互攻击也就是说任何两个皇后都不能处于同一条横行纵行或斜线上
//
//
//
// Related Topics 数组 回溯
// 👍 957 👎 0
package leetcode.editor.cn;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
//51:N 皇后
public class NQueens {
public static void main(String[] args) {
//测试代码
Solution solution = new NQueens().new Solution();
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
List<List<String>> result = new ArrayList<>();
public List<List<String>> solveNQueens(int n) {
StringBuilder str = new StringBuilder();
for (int i = 0; i < n; i++) {
str.append(".");
}
List<String> list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(str.toString());
}
bfs(list, n, 0);
return result;
}
private void bfs(List<String> list, int n, int row) {
if (row == list.size()) {
result.add(new ArrayList<>(list));
return;
}
for (int col = 0; col < n; col++) {
if (!isValid(list, row, col)) {
continue;
}
String temp = list.get(row);
String s1 = temp;
temp = temp.substring(0,col)+"Q"+temp.substring(col+1);
bfs(list,n,row+1);
}
}
private boolean isValid(List<String> list, int row, int col) {
int n = list.size();
for (String s : list) {
if (s.charAt(col) == 'Q') {
return false;
}
}
int r = row - 1;
int c = col + 1;
while (r >= 0 && c < n) {
if (list.get(r).charAt(c) == 'Q') {
return false;
}
r--;
c++;
}
r= row - 1;
c = col - 1;
while (r>=0&&c>=0){
if (list.get(r).charAt(c) == 'Q') {
return false;
}
r--;
c--;
}
return true;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,36 @@
<p><strong>n 皇后问题</strong> 研究的是如何将 <code>n</code> 个皇后放置在 <code>n×n</code> 的棋盘上,并且使皇后彼此之间不能相互攻击。</p>
<p>给你一个整数 <code>n</code> ,返回所有不同的 <strong>n<em> </em>皇后问题</strong> 的解决方案。</p>
<div class="original__bRMd">
<div>
<p>每一种解法包含一个不同的 <strong>n 皇后问题</strong> 的棋子放置方案,该方案中 <code>'Q'</code><code>'.'</code> 分别代表了皇后和空位。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/queens.jpg" style="width: 600px; height: 268px;" />
<pre>
<strong>输入:</strong>n = 4
<strong>输出:</strong>[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
<strong>解释:</strong>如上图所示4 皇后问题存在两个不同的解法。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 1
<strong>输出:</strong>[["Q"]]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= n <= 9</code></li>
<li>皇后彼此不能相互攻击,也就是说:任何两个皇后都不能处于同一条横行、纵行或斜线上。</li>
</ul>
</div>
</div>
<div><div>Related Topics</div><div><li>数组</li><li>回溯</li></div></div>\n<div><li>👍 957</li><li>👎 0</li></div>

View File

@ -0,0 +1,101 @@
// n 个网络节点标记为 1 n
//
// 给你一个列表 times表示信号经过 有向 边的传递时间 times[i] = (ui, vi, wi)其中 ui 是源节点vi 是目标节点 w
//i 是一个信号从源节点传递到目标节点的时间
//
// 现在从某个节点 K 发出一个信号需要多久才能使所有节点都收到信号如果不能使所有节点收到信号返回 -1
//
//
//
// 示例 1
//
//
//
//
//输入times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2
//输出2
//
//
// 示例 2
//
//
//输入times = [[1,2,1]], n = 2, k = 1
//输出1
//
//
// 示例 3
//
//
//输入times = [[1,2,1]], n = 2, k = 2
//输出-1
//
//
//
//
// 提示
//
//
// 1 <= k <= n <= 100
// 1 <= times.length <= 6000
// times[i].length == 3
// 1 <= ui, vi <= n
// ui != vi
// 0 <= wi <= 100
// 所有 (ui, vi) 对都 互不相同不含重复边
//
// Related Topics 深度优先搜索 广度优先搜索 最短路 优先队列
// 👍 312 👎 0
package leetcode.editor.cn;
import com.code.leet.entiy.TwoArray;
import java.util.Arrays;
//743:网络延迟时间
public class NetworkDelayTime {
public static void main(String[] args) {
//测试代码
Solution solution = new NetworkDelayTime().new Solution();
TwoArray twoArray = new TwoArray("[[2,1,1],[2,3,1],[3,4,1]]",true);
System.out.println(solution.networkDelayTime(twoArray.getArr(), 4, 2));
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public int networkDelayTime(int[][] times, int n, int k) {
final int INF = Integer.MAX_VALUE / 2;
int[][] g = new int[n][n];
for (int i = 0; i < n; ++i) {
Arrays.fill(g[i], INF);
}
for (int[] t : times) {
int x = t[0] - 1, y = t[1] - 1;
g[x][y] = t[2];
}
int[] dist = new int[n];
Arrays.fill(dist, INF);
dist[k - 1] = 0;
boolean[] used = new boolean[n];
for (int i = 0; i < n; ++i) {
int x = -1;
for (int y = 0; y < n; ++y) {
if (!used[y] && (x == -1 || dist[y] < dist[x])) {
x = y;
}
}
used[x] = true;
for (int y = 0; y < n; ++y) {
dist[y] = Math.min(dist[y], dist[x] + g[x][y]);
}
}
int ans = Arrays.stream(dist).max().getAsInt();
return ans == INF ? -1 : ans;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,45 @@
<p><code>n</code> 个网络节点,标记为 <code>1</code> 到 <code>n</code></p>
<p>给你一个列表 <code>times</code>,表示信号经过 <strong>有向</strong> 边的传递时间。 <code>times[i] = (u<sub>i</sub>, v<sub>i</sub>, w<sub>i</sub>)</code>,其中 <code>u<sub>i</sub></code> 是源节点,<code>v<sub>i</sub></code> 是目标节点, <code>w<sub>i</sub></code> 是一个信号从源节点传递到目标节点的时间。</p>
<p>现在,从某个节点 <code>K</code> 发出一个信号。需要多久才能使所有节点都收到信号?如果不能使所有节点收到信号,返回 <code>-1</code></p>
<p> </p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/05/23/931_example_1.png" style="height: 220px; width: 200px;" /></p>
<pre>
<strong>输入:</strong>times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2
<strong>输出:</strong>2
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>times = [[1,2,1]], n = 2, k = 1
<strong>输出:</strong>1
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>times = [[1,2,1]], n = 2, k = 2
<strong>输出:</strong>-1
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= k <= n <= 100</code></li>
<li><code>1 <= times.length <= 6000</code></li>
<li><code>times[i].length == 3</code></li>
<li><code>1 <= u<sub>i</sub>, v<sub>i</sub> <= n</code></li>
<li><code>u<sub>i</sub> != v<sub>i</sub></code></li>
<li><code>0 <= w<sub>i</sub> <= 100</code></li>
<li>所有 <code>(u<sub>i</sub>, v<sub>i</sub>)</code> 对都 <strong>互不相同</strong>(即,不含重复边)</li>
</ul>
<div><div>Related Topics</div><div><li>深度优先搜索</li><li>广度优先搜索</li><li></li><li>最短路</li><li>堆(优先队列)</li></div></div>\n<div><li>👍 312</li><li>👎 0</li></div>

View File

@ -0,0 +1,117 @@
//有一个二维矩阵 grid 每个位置要么是陆地记号为 0 要么是水域记号为 1
//
// 我们从一块陆地出发每次可以往上下左右 4 个方向相邻区域走能走到的所有陆地区域我们将其称为一座岛屿
//
// 如果一座岛屿 完全 由水域包围即陆地边缘上下左右所有相邻区域都是水域那么我们将其称为 封闭岛屿
//
// 请返回封闭岛屿的数目
//
//
//
// 示例 1
//
//
//
// 输入grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1
//,0,1],[1,1,1,1,1,1,1,0]]
//输出2
//解释
//灰色区域的岛屿是封闭岛屿因为这座岛屿完全被水域包围即被 1 区域包围
//
// 示例 2
//
//
//
// 输入grid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]
//输出1
//
//
// 示例 3
//
// 输入grid = [[1,1,1,1,1,1,1],
//  [1,0,0,0,0,0,1],
//  [1,0,1,1,1,0,1],
//  [1,0,1,0,1,0,1],
//  [1,0,1,1,1,0,1],
//  [1,0,0,0,0,0,1],
// [1,1,1,1,1,1,1]]
//输出2
//
//
//
//
// 提示
//
//
// 1 <= grid.length, grid[0].length <= 100
// 0 <= grid[i][j] <=1
//
// Related Topics 深度优先搜索 广度优先搜索 并查集 数组 矩阵
// 👍 83 👎 0
package leetcode.editor.cn;
import com.code.leet.entiy.TwoArray;
//1254:统计封闭岛屿的数目
public class NumberOfClosedIslands {
public static void main(String[] args) {
//测试代码
Solution solution = new NumberOfClosedIslands().new Solution();
TwoArray twoArray = new TwoArray("" +
"[[1,1,1,1,1,1,1,0]," +
"[1,0,0,0,0,1,1,0]," +
"[1,0,1,0,1,1,1,0]," +
"[1,0,0,0,0,1,0,1]," +
"[1,1,1,1,1,1,1,0]]",true
);
System.out.println(solution.closedIsland(twoArray.getArr()));
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
boolean[][] use;
int[] dx = new int[]{-1, 1, 0, 0};
int[] dy = new int[]{0, 0, -1, 1};
int count = 0;
boolean flag;
public int closedIsland(int[][] grid) {
use = new boolean[grid.length][grid[0].length];
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[0].length; j++) {
if (grid[i][j] == 0 && !use[i][j]) {
flag = true;
dfs(i, j, grid);
if (flag) {
count++;
}
}
}
}
return count;
}
private void dfs(int x, int y, int[][] grid) {
use[x][y] = true;
for (int i = 0; i < 4; i++) {
x += dx[i];
y += dy[i];
if (x < 0 || x >= grid.length || y < 0 || y >= grid[0].length) {
x -= dx[i];
y -= dy[i];
flag = false;
continue;
}
if (grid[x][y] == 0 && !use[x][y]) {
dfs(x, y, grid);
}
x -= dx[i];
y -= dy[i];
}
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,48 @@
<p>有一个二维矩阵 <code>grid</code>&nbsp;,每个位置要么是陆地(记号为&nbsp;<code>0</code> )要么是水域(记号为&nbsp;<code>1</code> )。</p>
<p>我们从一块陆地出发,每次可以往上下左右&nbsp;4 个方向相邻区域走,能走到的所有陆地区域,我们将其称为一座「<strong>岛屿</strong>」。</p>
<p>如果一座岛屿&nbsp;<strong>完全</strong>&nbsp;由水域包围,即陆地边缘上下左右所有相邻区域都是水域,那么我们将其称为 「<strong>封闭岛屿</strong>」。</p>
<p>请返回封闭岛屿的数目。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/11/07/sample_3_1610.png"></p>
<pre><strong>输入:</strong>grid = [[1,1,1,1,1,1,1,0],[1,0,0,0,0,1,1,0],[1,0,1,0,1,1,1,0],[1,0,0,0,0,1,0,1],[1,1,1,1,1,1,1,0]]
<strong>输出:</strong>2
<strong>解释:</strong>
灰色区域的岛屿是封闭岛屿,因为这座岛屿完全被水域包围(即被 1 区域包围)。</pre>
<p><strong>示例 2</strong></p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2019/11/07/sample_4_1610.png"></p>
<pre><strong>输入:</strong>grid = [[0,0,1,0,0],[0,1,0,1,0],[0,1,1,1,0]]
<strong>输出:</strong>1
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>grid = [[1,1,1,1,1,1,1],
&nbsp; [1,0,0,0,0,0,1],
&nbsp; [1,0,1,1,1,0,1],
&nbsp; [1,0,1,0,1,0,1],
&nbsp; [1,0,1,1,1,0,1],
&nbsp; [1,0,0,0,0,0,1],
[1,1,1,1,1,1,1]]
<strong>输出:</strong>2
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= grid.length, grid[0].length &lt;= 100</code></li>
<li><code>0 &lt;= grid[i][j] &lt;=1</code></li>
</ul>
<div><div>Related Topics</div><div><li>深度优先搜索</li><li>广度优先搜索</li><li>并查集</li><li>数组</li><li>矩阵</li></div></div>\n<div><li>👍 83</li><li>👎 0</li></div>

View File

@ -0,0 +1,105 @@
//给定一个只包含数字的字符串用以表示一个 IP 地址返回所有可能从 s 获得的 有效 IP 地址 你可以按任何顺序返回答案
//
// 有效 IP 地址 正好由四个整数每个整数位于 0 255 之间组成且不能含有前导 0整数之间用 '.' 分隔
//
// 例如"0.1.2.201" "192.168.1.1" 有效 IP 地址但是 "0.011.255.245""192.168.1.312"
// "192.168@1.1" 无效 IP 地址
//
//
//
// 示例 1
//
//
//输入s = "25525511135"
//输出["255.255.11.135","255.255.111.35"]
//
//
// 示例 2
//
//
//输入s = "0000"
//输出["0.0.0.0"]
//
//
// 示例 3
//
//
//输入s = "1111"
//输出["1.1.1.1"]
//
//
// 示例 4
//
//
//输入s = "010010"
//输出["0.10.0.10","0.100.1.0"]
//
//
// 示例 5
//
//
//输入s = "101023"
//输出["1.0.10.23","1.0.102.3","10.1.0.23","10.10.2.3","101.0.2.3"]
//
//
//
//
// 提示
//
//
// 0 <= s.length <= 3000
// s 仅由数字组成
//
// Related Topics 字符串 回溯
// 👍 638 👎 0
package leetcode.editor.cn;
import java.util.ArrayList;
import java.util.List;
//93:复原 IP 地址
public class RestoreIpAddresses {
public static void main(String[] args) {
//测试代码
Solution solution = new RestoreIpAddresses().new Solution();
solution.restoreIpAddresses("0279245587303");
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
private List<String> list;
public List<String> restoreIpAddresses(String s) {
if ("".equals(s) || s.length() > 12) {
return new ArrayList<>();
}
list = new ArrayList<>();
dfs(s, 1, 0, -1, "" + s.charAt(0));
return list;
}
private void dfs(String s, int index, int count, int pos, String str) {
if (count == 3) {
str += s.substring(str.length() - 3);
String num = str.substring(str.lastIndexOf(".") + 1);
if (num.length() == 1 || num.length() < 4 && !num.startsWith("0") && (Integer.parseInt(num) <= 255)) {
list.add(str);
}
return;
}
if (str.length() == s.length() + 3 || index == s.length()) {
return;
}
int cur = Integer.parseInt(s.substring(Math.max(pos, 0), index + 1));
int bef = Integer.parseInt(s.substring(Math.max(pos, 0), index));
if (cur <= 255 && bef > 0) {
dfs(s, index + 1, count, pos, str + s.charAt(index));
}
dfs(s, index + 1, count + 1, index, str + "." + s.charAt(index));
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,52 @@
<p>给定一个只包含数字的字符串,用以表示一个 IP 地址,返回所有可能从 <code>s</code> 获得的 <strong>有效 IP 地址 </strong>。你可以按任何顺序返回答案。</p>
<p><strong>有效 IP 地址</strong> 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 <code>0</code>),整数之间用 <code>'.'</code> 分隔。</p>
<p>例如:"0.1.2.201" 和 "192.168.1.1" 是 <strong>有效</strong> IP 地址,但是 "0.011.255.245"、"192.168.1.312" 和 "192.168@1.1" 是 <strong>无效</strong> IP 地址。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "25525511135"
<strong>输出:</strong>["255.255.11.135","255.255.111.35"]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "0000"
<strong>输出:</strong>["0.0.0.0"]
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "1111"
<strong>输出:</strong>["1.1.1.1"]
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>s = "010010"
<strong>输出:</strong>["0.10.0.10","0.100.1.0"]
</pre>
<p><strong>示例 5</strong></p>
<pre>
<strong>输入:</strong>s = "101023"
<strong>输出:</strong>["1.0.10.23","1.0.102.3","10.1.0.23","10.10.2.3","101.0.2.3"]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 <= s.length <= 3000</code></li>
<li><code>s</code> 仅由数字组成</li>
</ul>
<div><div>Related Topics</div><div><li>字符串</li><li>回溯</li></div></div>\n<div><li>👍 638</li><li>👎 0</li></div>

View File

@ -0,0 +1,137 @@
//给你二叉树的根结点 root 请你设计算法计算二叉树的 垂序遍历 序列
//
// 对位于 (row, col) 的每个结点而言其左右子结点分别位于 (row + 1, col - 1) (row + 1, col + 1) 树的
//根结点位于 (0, 0)
//
// 二叉树的 垂序遍历 从最左边的列开始直到最右边的列结束按列索引每一列上的所有结点形成一个按出现位置从上到下排序的有序列表如果同行同列上有多个结点
//按结点的值从小到大进行排序
//
// 返回二叉树的 垂序遍历 序列
//
//
//
// 示例 1
//
//
//输入root = [3,9,20,null,null,15,7]
//输出[[9],[3,15],[20],[7]]
//解释
// -1 只有结点 9 在此列中
// 0 只有结点 3 15 在此列中按从上到下顺序
// 1 只有结点 20 在此列中
// 2 只有结点 7 在此列中
//
// 示例 2
//
//
//输入root = [1,2,3,4,5,6,7]
//输出[[4],[2],[1,5,6],[3],[7]]
//解释
// -2 只有结点 4 在此列中
// -1 只有结点 2 在此列中
// 0 结点 1 5 6 都在此列中
// 1 在上面所以它出现在前面
// 5 6 位置都是 (2, 0) 所以按值从小到大排序5 6 的前面
// 1 只有结点 3 在此列中
// 2 只有结点 7 在此列中
//
//
// 示例 3
//
//
//输入root = [1,2,3,4,6,5,7]
//输出[[4],[2],[1,5,6],[3],[7]]
//解释
//这个示例实际上与示例 2 完全相同只是结点 5 6 在树中的位置发生了交换
//因为 5 6 的位置仍然相同所以答案保持不变仍然按值从小到大排序
//
//
//
// 提示
//
//
// 树中结点数目总数在范围 [1, 1000]
// 0 <= Node.val <= 1000
//
// Related Topics 深度优先搜索 广度优先搜索 哈希表 二叉树
// 👍 124 👎 0
package leetcode.editor.cn;
import com.code.leet.entiy.TreeNode;
import java.util.*;
//987:二叉树的垂序遍历
public class VerticalOrderTraversalOfABinaryTree {
public static void main(String[] args) {
//测试代码
Solution solution = new VerticalOrderTraversalOfABinaryTree().new Solution();
}
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
List<int[]> list = new ArrayList<>();
public List<List<Integer>> verticalTraversal(TreeNode root) {
dfs(root, 0, 0);
list.sort((a, b) -> {
if (a[0] != b[0]) {
return a[0] - b[0];
}
if (a[1] != b[1]) {
return a[1] - b[1];
}
return a[2] - b[2];
});
int size = list.size();
List<List<Integer>> result = new ArrayList<>();
List<Integer> temp = new ArrayList<>();
temp.add(list.get(0)[2]);
int col = list.get(0)[0];
for (int i = 1; i < size; i++) {
while (i < size && list.get(i)[0] == col) {
temp.add(list.get(i)[2]);
i++;
}
if (i == size) {
break;
}
result.add(temp);
temp = new ArrayList<>();
temp.add(list.get(i)[2]);
col = list.get(i)[0];
}
result.add(temp);
return result;
}
private void dfs(TreeNode root, int row, int col) {
list.add(new int[]{col, row, root.val});
if (root.left != null) {
dfs(root.left, row + 1, col - 1);
}
if (root.right != null) {
dfs(root.right, row + 1, col + 1);
}
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,54 @@
<p>给你二叉树的根结点 <code>root</code> ,请你设计算法计算二叉树的<em> </em><strong>垂序遍历</strong> 序列。</p>
<p>对位于 <code>(row, col)</code> 的每个结点而言,其左右子结点分别位于 <code>(row + 1, col - 1)</code> 和 <code>(row + 1, col + 1)</code> 。树的根结点位于 <code>(0, 0)</code></p>
<p>二叉树的 <strong>垂序遍历</strong> 从最左边的列开始直到最右边的列结束,按列索引每一列上的所有结点,形成一个按出现位置从上到下排序的有序列表。如果同行同列上有多个结点,则按结点的值从小到大进行排序。</p>
<p>返回二叉树的 <strong>垂序遍历</strong> 序列。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/29/vtree1.jpg" style="width: 431px; height: 304px;" />
<pre>
<strong>输入:</strong>root = [3,9,20,null,null,15,7]
<strong>输出:</strong>[[9],[3,15],[20],[7]]
<strong>解释:</strong>
列 -1 :只有结点 9 在此列中。
列 0 :只有结点 3 和 15 在此列中,按从上到下顺序。
列 1 :只有结点 20 在此列中。
列 2 :只有结点 7 在此列中。</pre>
<p><strong>示例 2</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/29/vtree2.jpg" style="width: 512px; height: 304px;" />
<pre>
<strong>输入:</strong>root = [1,2,3,4,5,6,7]
<strong>输出:</strong>[[4],[2],[1,5,6],[3],[7]]
<strong>解释:</strong>
列 -2 :只有结点 4 在此列中。
列 -1 :只有结点 2 在此列中。
列 0 :结点 1 、5 和 6 都在此列中。
1 在上面,所以它出现在前面。
5 和 6 位置都是 (2, 0) 所以按值从小到大排序5 在 6 的前面。
列 1 :只有结点 3 在此列中。
列 2 :只有结点 7 在此列中。
</pre>
<p><strong>示例 3</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/29/vtree3.jpg" style="width: 512px; height: 304px;" />
<pre>
<strong>输入:</strong>root = [1,2,3,4,6,5,7]
<strong>输出:</strong>[[4],[2],[1,5,6],[3],[7]]
<strong>解释:</strong>
这个示例实际上与示例 2 完全相同,只是结点 5 和 6 在树中的位置发生了交换。
因为 5 和 6 的位置仍然相同,所以答案保持不变,仍然按值从小到大排序。</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li>树中结点数目总数在范围 <code>[1, 1000]</code></li>
<li><code>0 <= Node.val <= 1000</code></li>
</ul>
<div><div>Related Topics</div><div><li></li><li>深度优先搜索</li><li>广度优先搜索</li><li>哈希表</li><li>二叉树</li></div></div>\n<div><li>👍 124</li><li>👎 0</li></div>

File diff suppressed because one or more lines are too long