面试时间:2021.8.16
自我介绍 聊之前项目(使用的框架,遇到的问题,如何解决,有啥看法感悟)(感觉面试官自己也不知道问啥,所以这里就聊了足足半小时…) Vue和React的区别你有什么看法
编程题
function TreeNode(v) {
this.val = v;
this.left = this.right = null;
}
const root = new TreeNode(1);
root.left = new TreeNode(2);
root.right = new TreeNode(3);
root.left.left = new TreeNode(4);
root.left.right = new TreeNode(5);
root.right.left = new TreeNode(6);
root.right.right = new TreeNode(7);
level(root);
function level(root){
if(root == null) return;
let result = [];
let queue = [root];
while(queue.length > 0){
let currentLevel = [];
let len = queue.length;
for(let i=0; i<len; i++){
let currentNode = queue.shift();
currentLevel.push(currentNode.val);
if(currentNode.left) queue.push(currentNode.left);
if(currentNode.right) queue.push(currentNode.right);
}
result.push(currentLevel);
}
for(let i=result.length - 1; i>=0; i--){
let str = "";
for(let j=result[i].length - 1; j>=0; j--){
str = str + result[i][j] + " ";
}
console.log(str.trim());
}
}
function find(root, target){
if(root == null) return [];
return helper(root, target, []);
function helper(node,target,path){
path = Array.from(path);
if(node.val == target){
return [...path,node.val];
}
if(node.left) {
let res = helper(node.left, target, [...path,node.val]);
if(res.length != 0){
return res;
}
}
if(node.right) {
let res = helper(node.right, target, [...path,node.val]);
if(res.length != 0){
return res;
}
}
return [];
}
}
|