25秋招 | 快手一面
- 项目问题 20min
- 到这里就开始做题了
- Q1(5min)
// 数组扁平, 不能用flat;数组排序不能用sort
// 期望输出: [0, 1, 2, 3, 4, 6, 7]
const data = [[[]], [3], [0], 4, [2, 1], [[7, [[[[6]]]]]]];
这题我写了个拍平函数写了个快排
- Q2:一道输入输出题目(3min)
async function async1() {
console.log('async1 start');
await async2();
console.log('async1 end');
}
async function async2() {
console.log('async2');
}
console.log('script start');
setTimeout(function() {
console.log('setTimeout');
}, 0);
async1();
new Promise(function(resolve) {
console.log('promise1');
resolve();
}).then(function() {
console.log('promise2');
});
console.log('script end');
- Q3:把当前二叉树的右节点移动到左节点的右节点。(15min)
- 写出来一个有瑕疵的版本,有无大佬可以教一下
function test(root){
function deal(root, lrNodeTemp) {
if (!root) {
return;
}
if (!root.left && !root.right) {
return;
}
let rightNode, lrNode;
if (root.right) {
rightNode = root.right;
if (lrNodeTemp === null) root.right = null;
}
if (root.left) {
if (root.left.right) {
lrNode = root.left.right;
}
}
if (root.left) {
root.left.right = lrNodeTemp !== null ? lrNodeTemp : rightNode ;
}
deal(root.left, lrNode);
}
deal(root, null);
return root;
}
let tree1 = {
val: "A",
left:{
val: "B",
left:{
val: "D",
},
right:{
val: "E"
}
},
right:{
val: "C"
}
}
let result = test(tree1)
console.log(JSON.stringify(result),'result')
#快手求职进展汇总##九月投秋招是不是太晚了?##软件开发笔面经#
顺丰集团工作强度 389人发布