const find = (arr,nid) =>{
let res = '123'
function dfs(obj){
if (obj.id === nid){
res = obj.name;
return
}
for (let j = 0 ; j< obj.children.length ; j++){
dfs(obj.children[j])
}
}
for (let i = 0 ; i< arr.length ;i++){
dfs(arr[i])
}
return res
}
var data = [
{
id: '100',
name: '上海',
children: [
{
id: '101',
name: '浦东',
children: [
]
},
{
id: '102',
name: '浦西',
children: []
}
]
},
{
id: '200',
name: '杭州',
children: [
{
id: '201',
name: '西湖区',
children: [{
id: '221',
name: '蚂蚁 A 空间',
children: []
}]
},
{
id: '202',
name: '余杭区',
children: []
}
]
}
];
console.log(find(data, '102'))
let s = "pwiwkew"
function utils(s){
const nmap = new Map()
const queue = []
let max = 0
for (let i = 0 ; i < s.length ; i++){
while(nmap.has(s[i])){
const node = queue.shift()
nmap.delete(node)
}
queue.push(s[i])
nmap.set(s[i],i)
max = Math.max(queue.length , max)
}
return max
}
console.log(utils(s))
console