Skip to content

Commit 326d8e4

Browse files
committedMar 28, 2025
Add solution #958
1 parent aacba38 commit 326d8e4

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,043 LeetCode solutions in JavaScript
1+
# 1,044 LeetCode solutions in JavaScript
22

33
[https://leetcode.com/](https://leetcode.com/)
44

@@ -767,6 +767,7 @@
767767
955|[Delete Columns to Make Sorted II](./solutions/0955-delete-columns-to-make-sorted-ii.js)|Medium|
768768
956|[Tallest Billboard](./solutions/0956-tallest-billboard.js)|Hard|
769769
957|[Prison Cells After N Days](./solutions/0957-prison-cells-after-n-days.js)|Medium|
770+
958|[Check Completeness of a Binary Tree](./solutions/0958-check-completeness-of-a-binary-tree.js)|Medium|
770771
966|[Vowel Spellchecker](./solutions/0966-vowel-spellchecker.js)|Medium|
771772
970|[Powerful Integers](./solutions/0970-powerful-integers.js)|Easy|
772773
976|[Largest Perimeter Triangle](./solutions/0976-largest-perimeter-triangle.js)|Easy|
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* 958. Check Completeness of a Binary Tree
3+
* https://leetcode.com/problems/check-completeness-of-a-binary-tree/
4+
* Difficulty: Medium
5+
*
6+
* Given the root of a binary tree, determine if it is a complete binary tree.
7+
*
8+
* In a complete binary tree, every level, except possibly the last, is completely filled, and
9+
* all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes
10+
* inclusive at the last level h.
11+
*/
12+
13+
/**
14+
* Definition for a binary tree node.
15+
* function TreeNode(val, left, right) {
16+
* this.val = (val===undefined ? 0 : val)
17+
* this.left = (left===undefined ? null : left)
18+
* this.right = (right===undefined ? null : right)
19+
* }
20+
*/
21+
/**
22+
* @param {TreeNode} root
23+
* @return {boolean}
24+
*/
25+
var isCompleteTree = function(root) {
26+
const queue = [root];
27+
let foundNull = false;
28+
29+
while (queue.length) {
30+
const node = queue.shift();
31+
if (!node) {
32+
foundNull = true;
33+
continue;
34+
}
35+
if (foundNull) return false;
36+
queue.push(node.left);
37+
queue.push(node.right);
38+
}
39+
40+
return true;
41+
};

0 commit comments

Comments
 (0)
Please sign in to comment.