Balanced Binary Tree - Solution | Binary Trees | Data Structure and Algorithms in JAVA

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


#pepcoding #java #programming

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

"Risk Hai", cheered me up. The way of including memes to get the question and solution interesting is AWESOME!! Thanks @Pepcoding for making easy to understand videos!!

satyamsinha
Автор

sir i checked other videos but aap ne to kuch jda hi khtrnaak smjha diya
mjaa aa gya

sangamchoudhary
Автор

Sir that "risk hai" part was awesome. You have one of the best way of teaching

shridharsarraf
Автор

Your content is awesome ❤️.
I became noob to pro in tree from your channel .

aakashshivanshu
Автор

Sir Ji Kya Hi Smjhaya . Saari videos Dekhli Sbse Best yaha Clear hua Ki Sala ho Kya rha tha ques me .Thanks :D

tejastaneja
Автор

This one is also good approach with O(N)

class Solution {

boolean flag = true;
public boolean isBalanced(TreeNode root) {

height(root);
return flag;
}

public int height(TreeNode root){
if(root == null) return 0;

int lh = height(root.left);
int rh = height(root.right);

if(Math.abs(lh-rh) >1){
flag = false;
return 0;
}

return 1+Math.max(lh, rh);

}
}

vyankateshkulkarni
Автор

I tried with different Method ... still code is getting submitted, hence TestCases are weak .KINDLY CHECK .THANK YOU

_akshat
Автор

Sir first vale code ki tc o(n) hogi na?

manjugoswami
Автор

sir does first code without pair work when the tree is not balanced in middle but it is balanced from the root because isBal would change to true at the top when the root is balanced

santoshkumar-shsb
Автор

sir, AVL trees, red black trees ki bhi playlist banayenge kya aap

namansinghal
Автор

Sir, hme c++ mein codes mil jayenge kya?

danealvez
Автор

Sir travel and change and pair bnane me bas yhi ferk hai ki wo static ho rakha hai to kisi bhi function me hem change ker rhe hai wo Sare function me reflect hoga aur ager hem ye nhi kerna chahte hai to hme pair bnanan pdega ek class jisme hem ek sath usko bhi bheg paye jo hem static bnaye the travel and change method me

SCRIPTSAG
Автор

sir i am facing problems in tree. main jo bhi question kar rha hu uski pehle se defination define hai usko karne ka vai tareeka hai defination nahi aati hai toh question hote ni ...do din se 10 me se sirf ek question ban rha hai khud se baaki aapki help leni pad rhi hai....sir in question me aisa hota hi hai ya sirf main hi akela demotivate ho rha hu .

AnkitSharma-wjtb
Автор

class Solution {
static boolean isBal = true;
public boolean isBalanced(TreeNode root) {
if(root == null)
return isBal;

solve(root);
return isBal;
}
public int solve(TreeNode n){
if(n == null)
return 0;

int lh=solve(n.left);
int rh=solve(n.right);

int gap=Math.abs(lh-rh);
if(gap > 1)
isBal=false;

return 1+Math.max(lh, rh);
}
}

what's the mistake giving wrong ans.for leetcode?

manavmalhotra
Автор

public static int size(Node node)
{
if(node==null)
{
return 0;
}
int left=size(node.left);
int right=size(node.right);
return left+right+3;
}
public static boolean isbalance(Node node)
{
if(node==null)
{
return true;
}
int lefts=size(node.left);
int rights=size(node.right);
if(lefts-rights>1)
{
return false;
}
return true;
}

amandixit
Автор

Anybody having second approach code in C++ plz share in comment

adityagoyal
join shbcf.ru