Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1a1bbf0

Browse files
✨feat: Add 467 & 965
1 parent 49dc10e commit 1a1bbf0

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed

‎Index/BFS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
| [821. 字符的最短距离](https://leetcode-cn.com/problems/shortest-distance-to-a-character/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/shortest-distance-to-a-character/solution/by-ac_oier-5bjs/) | 简单 | 🤩🤩🤩🤩 |
1515
| [838. 推多米诺](https://leetcode-cn.com/problems/push-dominoes/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/push-dominoes/solution/gong-shui-san-xie-yi-ti-shuang-jie-bfs-y-z52w/) | 中等 | 🤩🤩🤩🤩 |
1616
| [938. 二叉搜索树的范围和](https://leetcode-cn.com/problems/range-sum-of-bst/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/range-sum-of-bst/solution/gong-shui-san-xie-yi-ti-shuang-jie-di-gu-q2fo/) | 简单 | 🤩🤩🤩 |
17+
| [965. 单值二叉树](https://leetcode.cn/problems/univalued-binary-tree/) | [LeetCode 题解链接](https://leetcode.cn/problems/univalued-binary-tree/solution/by-ac_oier-zxjl/) | 简单 | 🤩🤩🤩🤩 |
1718
| [993. 二叉树的堂兄弟节点](https://leetcode-cn.com/problems/cousins-in-binary-tree/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/cousins-in-binary-tree/solution/gong-shui-san-xie-shu-de-sou-suo-dfs-bfs-b200/) | 简单 | 🤩🤩 |
1819
| [1609. 奇偶树](https://leetcode-cn.com/problems/even-odd-tree/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/even-odd-tree/solution/gong-shui-san-xie-yi-ti-shuang-jie-bfs-d-kuyi/) | 中等 | 🤩🤩🤩🤩🤩 |
1920

‎Index/DFS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
| [869. 重新排序得到 2 的幂](https://leetcode-cn.com/problems/reordered-power-of-2/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/reordered-power-of-2/solution/gong-shui-san-xie-yi-ti-shuang-jie-dfs-c-3s1e/) | 中等 | 🤩🤩🤩🤩 |
3333
| [872. 叶子相似的树](https://leetcode-cn.com/problems/leaf-similar-trees/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/leaf-similar-trees/solution/gong-shui-san-xie-yi-ti-shuang-jie-di-gu-udfc/) | 简单 | 🤩🤩🤩 |
3434
| [938. 二叉搜索树的范围和](https://leetcode-cn.com/problems/range-sum-of-bst/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/range-sum-of-bst/solution/gong-shui-san-xie-yi-ti-shuang-jie-di-gu-q2fo/) | 简单 | 🤩🤩🤩 |
35+
| [965. 单值二叉树](https://leetcode.cn/problems/univalued-binary-tree/) | [LeetCode 题解链接](https://leetcode.cn/problems/univalued-binary-tree/solution/by-ac_oier-zxjl/) | 简单 | 🤩🤩🤩🤩 |
3536
| [987. 二叉树的垂序遍历](https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree/solution/gong-shui-san-xie-yi-ti-shuang-jie-dfs-h-wfm3/) | 困难 | 🤩🤩🤩🤩🤩 |
3637
| [993. 二叉树的堂兄弟节点](https://leetcode-cn.com/problems/cousins-in-binary-tree/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/cousins-in-binary-tree/solution/gong-shui-san-xie-shu-de-sou-suo-dfs-bfs-b200/) | 简单 | 🤩🤩 |
3738
| [1239. 串联字符串的最大长度](https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/solution/gong-shui-san-xie-yi-ti-san-jie-jian-zhi-nfeb/) | 中等 | 🤩🤩🤩 |

‎Index/二叉树.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| [783. 二叉搜索树节点最小距离](https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/solution/gong-shui-san-xie-yi-ti-san-jie-shu-de-s-7r17/) | 简单 | 🤩🤩🤩 |
1212
| [863. 二叉树中所有距离为 K 的结点](https://leetcode-cn.com/problems/all-nodes-distance-k-in-binary-tree/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/all-nodes-distance-k-in-binary-tree/solution/gong-shui-san-xie-yi-ti-shuang-jie-jian-x6hak/) | 中等 | 🤩🤩🤩🤩 |
1313
| [938. 二叉搜索树的范围和](https://leetcode-cn.com/problems/range-sum-of-bst/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/range-sum-of-bst/solution/gong-shui-san-xie-yi-ti-shuang-jie-di-gu-q2fo/) | 简单 | 🤩🤩🤩 |
14+
| [965. 单值二叉树](https://leetcode.cn/problems/univalued-binary-tree/) | [LeetCode 题解链接](https://leetcode.cn/problems/univalued-binary-tree/solution/by-ac_oier-zxjl/) | 简单 | 🤩🤩🤩🤩🤩 |
1415
| [987. 二叉树的垂序遍历](https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/vertical-order-traversal-of-a-binary-tree/solution/gong-shui-san-xie-yi-ti-shuang-jie-dfs-h-wfm3/) | 困难 | 🤩🤩🤩🤩🤩 |
1516
| [993. 二叉树的堂兄弟节点](https://leetcode-cn.com/problems/cousins-in-binary-tree/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/cousins-in-binary-tree/solution/gong-shui-san-xie-shu-de-sou-suo-dfs-bfs-b200/) | 简单 | 🤩🤩 |
1617
| [1104. 二叉树寻路](https://leetcode-cn.com/problems/path-in-zigzag-labelled-binary-tree/) | [LeetCode 题解链接](https://leetcode-cn.com/problems/path-in-zigzag-labelled-binary-tree/solution/gong-shui-san-xie-yi-ti-shuang-jie-mo-ni-rw2d/) | 中等 | 🤩🤩🤩 |

‎LeetCode/461-470/467. 环绕字符串中唯一的子字符串(中等).md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### 题目描述
22

3-
这是 LeetCode 上的 **[467. 环绕字符串中唯一的子字符串](https://leetcode.cn/problems/can-i-win/solution/by-ac_oier-0ed9/)** ,难度为 **中等**
3+
这是 LeetCode 上的 **[467. 环绕字符串中唯一的子字符串](https://leetcode.cn/problems/unique-substrings-in-wraparound-string/solution/by-ac_oier-qteu/)** ,难度为 **中等**
44

55
Tag : 「线性 DP」、「树状数组」
66

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
### 题目描述
2+
3+
这是 LeetCode 上的 **[965. 单值二叉树](https://leetcode.cn/problems/univalued-binary-tree/solution/by-ac_oier-zxjl/)** ,难度为 **简单**
4+
5+
Tag : 「DFS」、「BFS」、「二叉树」、「树的遍历」、「层序遍历」
6+
7+
8+
9+
如果二叉树每个节点都具有相同的值,那么该二叉树就是单值二叉树。
10+
11+
只有给定的树是单值二叉树时,才返回 `true`;否则返回 `false`
12+
13+
示例 1:
14+
![](https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/29/screen-shot-2018年12月25日-at-50104-pm.png)
15+
```
16+
输入:[1,1,1,1,1,null,1]
17+
18+
输出:true
19+
```
20+
示例 2:
21+
![](https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/12/29/screen-shot-2018年12月25日-at-50050-pm.png)
22+
```
23+
输入:[2,2,2,5,2]
24+
25+
输出:false
26+
```
27+
28+
提示:
29+
* 给定树的节点数范围是 $[1, 100]\。
30+
* 每个节点的值都是整数,范围为 $[0, 99]$ 。
31+
32+
---
33+
34+
### 递归
35+
36+
根据题意进行模拟即可。
37+
38+
代码:
39+
```Java
40+
class Solution {
41+
int val = -1;
42+
public boolean isUnivalTree(TreeNode root) {
43+
if (val == -1) val = root.val;
44+
if (root == null) return true;
45+
if (root.val != val) return false;
46+
return isUnivalTree(root.left) && isUnivalTree(root.right);
47+
}
48+
}
49+
```
50+
* 时间复杂度:$O(n)$
51+
* 空间复杂度:忽略递归带来的额外空间消耗,复杂度为 $O(1)$
52+
53+
---
54+
55+
### 迭代
56+
57+
也可以使用迭代的方式进行层序遍历。
58+
59+
代码:
60+
```Java
61+
class Solution {
62+
public boolean isUnivalTree(TreeNode root) {
63+
int val = root.val;
64+
Deque<TreeNode> d = new ArrayDeque<>();
65+
d.addLast(root);
66+
while (!d.isEmpty()) {
67+
TreeNode poll = d.pollFirst();
68+
if (poll.val != val) return false;
69+
if (poll.left != null) d.addLast(poll.left);
70+
if (poll.right != null) d.addLast(poll.right);
71+
}
72+
return true;
73+
}
74+
}
75+
```
76+
* 时间复杂度:$O(n)$
77+
* 空间复杂度:$O(n)$
78+
79+
---
80+
81+
### 最后
82+
83+
这是我们「刷穿 LeetCode」系列文章的第 `No.965` 篇,系列开始于 2021年01月01日,截止于起始日 LeetCode 上共有 1916 道题目,部分是有锁题,我们将先把所有不带锁的题目刷完。
84+
85+
在这个系列文章里面,除了讲解解题思路以外,还会尽可能给出最为简洁的代码。如果涉及通解还会相应的代码模板。
86+
87+
为了方便各位同学能够电脑上进行调试和提交代码,我建立了相关的仓库:https://github.com/SharingSource/LogicStack-LeetCode
88+
89+
在仓库地址里,你可以看到系列文章的题解链接、系列文章的相应代码、LeetCode 原题链接和其他优选题解。
90+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /