## [965\. 单值二叉树](https://leetcode-cn.com/problems/univalued-binary-tree/)
>Easy
#### 思路
判断有没有其他数字,那肯定就是要遍历二叉树。记录节点值,判断当前节点是否与其他的节点不同。遍历二叉树,也就是深度优先和广度优先,这边选用DFS。
尝试写一下代码,AC!
#### 代码
python3
```
class Solution:
def dfs(self, val, node):
if node is None:
return True
if node.val != val:
return False
return self.dfs(val, node.left) and self.dfs(val, node.right)
def isUnivalTree(self, root: TreeNode) -> bool:
if root is None:
return True
val = root.val
return self.dfs(val, root)
```
- 目录
- excel-sheet-column-number
- divide-two-integers
- house-robber
- fraction-to-recurring-decimal
- profile
- kids-with-the-greatest-number-of-candies
- qiu-12n-lcof
- new-21-game
- product-of-array-except-self
- minimum-depth-of-binary-tree
- univalued-binary-tree
- shun-shi-zhen-da-yin-ju-zhen-lcof
- permutations
- satisfiability-of-equality-equations
- word-ladder-ii
- ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof
- palindrome-number
- network-delay-time
- daily-temperatures
- longest-common-prefix
- sum-of-mutated-array-closest-to-target
- 周赛专题
- make-two-arrays-equal-by-reversing-sub-arrays
- check-if-a-string-contains-all-binary-codes-of-size-k
- course-schedule-iv
- cherry-pickup-ii
- maximum-product-of-two-elements-in-an-array
- maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts
- reorder-routes-to-make-all-paths-lead-to-the-city-zero
- probability-of-a-two-boxes-having-the-same-number-of-distinct-balls
- shuffle-the-array
- the-k-strongest-values-in-an-array
- design-browser-history
- paint-house-iii
- final-prices-with-a-special-discount-in-a-shop