Check Completeness of a Binary Tree - Leetcode 958 - Python

preview_player
Показать описание


0:00 - Read the problem
1:20 - Drawing Explanation
5:10 - Coding Explanation

leetcode 958

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

Key is once you find a null node, you mustn't get any other non null node from the tree..if there is the return false.

rithickchowdhury
Автор

Very clear:) even for someone with very little dsa experience, thanks!

Vancha
Автор

Beautiful solution, I write 1 page long of code for this problem ...

tuandino
Автор

You make it very easy to understand. So, when I am stuck on a problem. I go to your channel

shubhamsharma
Автор

My solution was similar in principle but a lot longer. Thanks for sharing this, very succinct!

victoriatfarrell
Автор

Still making great videos, keep up the great work. I like that I can pretty much solve it just from your explanation before you even show the code.

sergiohernandez
Автор

so brilliant... I just came out with some bad methods and messy code

Tim_desu
Автор

What does he use for drawing? How do you draw in the same page as the question? Do you use an iPad to draw and write?

x
Автор

Could someone help me understand why the space complexity not O(log n) which is the height of the three?

akshitaven
Автор

C++ implementation

bool isCompleteTree(TreeNode* root) {

bool flag = false;

queue<TreeNode*> q;
q.push(root);

while (!q.empty()) {
int n = q.size();

for (int i = 0; i < n; i++) {
TreeNode* node = q.front();
q.pop();

if (!node) {
flag = true;
} else {
if (flag) {
return false;
}

q.push(node->left);
q.push(node->right);
}
}
}


return true;
}

shubhamraj