Skip to content

Commit 8940540

Browse files
committed
75
1 parent a4cc8d6 commit 8940540

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Day75/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val, left, right) {
4+
* this.val = (val===undefined ? 0 : val)
5+
* this.left = (left===undefined ? null : left)
6+
* this.right = (right===undefined ? null : right)
7+
* }
8+
*/
9+
/**
10+
* @param {TreeNode} root
11+
* @return {boolean}
12+
*/
13+
var isBalanced = function(root) {
14+
let flag = true
15+
16+
height(root);
17+
return flag;
18+
19+
function height(node){
20+
if(!node)return 0;
21+
22+
if(!flag) return;
23+
24+
let left = height(node.left);
25+
let right = height(node.right);
26+
27+
//check
28+
if(Math.abs(left-right) > 1)flag = false
29+
30+
return Math.max(left,right)+1
31+
}
32+
};

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,6 @@ If you are loving solving problems in leetcode, please contact me to enjoy it to
166166

167167
|Day 73| [910. Smallest Range II](https://leetcode.com/problems/smallest-range-ii/) | [javascript]()|[:memo:](https://leetcode.com/problems/smallest-range-ii/)|Easy|
168168

169-
|Day 74| [1602. Find Nearest Right Node in Binary Tree](https://leetcode.com/problems/find-nearest-right-node-in-binary-tree/) | [javascript]()|[:memo:](https://leetcode.com/problems/find-nearest-right-node-in-binary-tree/)|Medium|
169+
|Day 74| [1602. Find Nearest Right Node in Binary Tree](https://leetcode.com/problems/find-nearest-right-node-in-binary-tree/) | [javascript]()|[:memo:](https://leetcode.com/problems/find-nearest-right-node-in-binary-tree/)|Medium|
170+
171+
|Day 75| [110. Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [javascript]()|[:memo:](https://leetcode.com/problems/balanced-binary-tree/)|Easy|

0 commit comments

Comments
 (0)