var mirrorTree = function(root) {
if (root === null) {
return null
}
const left=mirrorTree(root.left)
const right=mirrorTree(root.right)
root.left=right
root.right=left
return root
}
var isSymmetric = function(root) {
if(JSON.stringify(root)===JSON.stringify(mirror(root))){
return true
}
return false
};
const mirror=(root)=>{
if(root===null){
return null
}
let left=mirror(root.left)
let right=mirror(root.right)
root.left=right
root.right=left
return root
}
var isSymmetric = function(root) {
if(root===null)return true
const compare=(left,right)=>{
if(!left && !right)return true
if(!left || !right)return false
return left.val===right.val && compare(left.left,right.right) && compare(left.right,right.left)
}
return compare(root.left,root.right)
};
var levelOrder = function(root) {
if(!root)return []
let res=[]
let queue=[root]
while(queue.length>0){
let l=queue.length
let cur=[]
for(let i=0;i<l;i++){
let node=queue.shift()
cur.push(node.val)
if(node.left){
queue.push(node.left)
}
if(node.right){
queue.push(node.right)
}
}
res.push(cur)
}
return res
};
var kthLargest = function(root, k) {
if(!root)return 0
let res=[]
const dfs=(node)=>{
if(!node)return
dfs(node.right)
res.push(node.val)
dfs(node.left)
}
dfs(root)
return res[k-1]
};
var maxDepth = function(root) {
if(!root)return 0
return 1+Math.max(maxDepth(root.left),maxDepth(root.right))
};