海康威视笔试vue9.14
想不通为什么深搜有问题,求某佬指点一下...
function findNode(tree, target) {
if (tree.name === target) {
return tree.val;
}
if (tree.children) {
for (const child of tree.children) {
const result = findNode(child, target);
if (result) {
return result;
}
}
}
return null;
}
// 输入的树结构
const tree = {
val: 'rootVal',
name: 'rootName',
children: [
{
val: 'childVal',
name: 'childName',
children: [
{
val: 'child1-1Val',
name: 'child1-1Name'
}
]
},
{
val: 'child2Val',
name: 'child2Name'
}
]
};
// 输入的目标节点名称
const target = 'rootName';
const result = findNode(tree, target);
console.log(result);
function findNode(tree, target) {
if (tree.name === target) {
return tree.val;
}
if (tree.children) {
for (const child of tree.children) {
const result = findNode(child, target);
if (result) {
return result;
}
}
}
return null;
}
// 输入的树结构
const tree = {
val: 'rootVal',
name: 'rootName',
children: [
{
val: 'childVal',
name: 'childName',
children: [
{
val: 'child1-1Val',
name: 'child1-1Name'
}
]
},
{
val: 'child2Val',
name: 'child2Name'
}
]
};
// 输入的目标节点名称
const target = 'rootName';
const result = findNode(tree, target);
console.log(result);
全部评论
兄弟,试试光伏电池行业~
相关推荐
点赞 评论 收藏
分享
在看数据的卡尔很调皮:建议学学react吧,大厂大部分都是react。然后实习面试的话八股最重要,算法hot100就够了,项目的话整理一下常见问答就好了。多投多面吧,学历够没必要去小厂,坚持面大厂总会找到,多沉淀沉淀 点赞 评论 收藏
分享
