DAY 5
112. Path Sum (Easy)
113. Path Sum II (Medium)
101. Symmetric Tree (Easy)
DAY6
124. Binary Tree Maximum Path Sum (Hard)
199. Binary Tree Right Side View (Medium)
var rightSideView = function(root) {
let queue = [];
let res = [];
queue.push(root);
if (root === null) return res;
while(queue.length !== 0) {
let length = queue.length;
let level = [];
for(let i =0; i < length; i++){
let node = queue.shift();
level.push(node.val);
if(node.left) {queue.push(node.left);}
if(node.right) {queue.push(node.right);}
}
res.push(level[length-1]);
}
return res;
};
226. Invert Binary Tree (Easy)
var invertTree = function(root) {
const invertNode = function(root, left, right) {
let temp = left;
left = right;
right = temp;
root.right = right;
root.left = left;
}
const queue = [root];
if(root === null) return root;
while (queue.length) {
let length = queue.length;
while(length--) {
let node = queue.shift();
invertNode(node, node.left, node.right);
if (node.left) queue.push(node.left);
if (node.right) queue.push(node.right);
}
}
return root;
};