i swear apki videoss mai ye question ekdam shai kar rha tha bass ek choti si mistake thi ajise hi apki video explanation dekhi ho gaya solve question
@codestorywithMIK Жыл бұрын
Awesome 🙏😇
@JJ-tp2dd Жыл бұрын
Thanks, bhai. Below is the Java Implementation : TC O(N) and space Complexity O(logN) i.e. height of tree (for the recursive stack used) class Solution { private boolean solve(TreeNode l, TreeNode r) { // both of them are null if(l == null && r == null) { return true; } // only one of them is null if(l == null || r == null) { return false; } // the values are different if(l.val != r.val) { return false; } return solve(l.left, r.right) && solve(l.right, r.left); } public boolean isSymmetric(TreeNode root) { return solve(root.left, root.right); } }
Java Code if any one want : class Solution { boolean check( TreeNode left , TreeNode right ){ if( left == null && right == null) // if both are null then it is symmetric return true; if( left == null || right == null ) // if one of them is true means it is not symmetric return false; boolean oneSide = check( left.left , right.right); // checking one side of tree boolean anotherSide = check( left.right , right.left); //checking anotherSide of tree if( (left.val == right.val) && oneSide && anotherSide ) return true; // if values are equal and both recursive conditions are equal then also true return false; } public boolean isSymmetric(TreeNode root) { if (root == null) return true; return check( root.left , root.right); } }
@shloksuman8164 Жыл бұрын
thanks for this simple explanation, it became very clear to me
@codestorywithMIK Жыл бұрын
So glad
@Shubham_Singh841 Жыл бұрын
Great
@MaheshPatil-of1zy9 ай бұрын
how to build logic for these type of tree questions? means which approach can we use? how to decide that?
@venkatarohitpotnuru384 ай бұрын
Bhaiyya ka videos dekheke concept build karna hoga
@elakstein Жыл бұрын
Udemy se konsa course kar rahe bhai.
@codestorywithMIK Жыл бұрын
Recently i did Elastic search and Go
@guptashashwat Жыл бұрын
@@codestorywithMIK Go ka course kaisa hai bhai? Lene layak hai? I want to learn GO