function tree(array) {
let treeNodes = new Map()
let rootNode
array.forEach((item) => {
if (!treeNodes.has(item.c)) {
let newNode = {
val: item.c,
children: []
}
treeNodes.set(item.c,newNode)
}
let childNode = treeNodes.get(item.c)
if (!treeNodes.has(item.p)) {
let newNode = {
val: item.p,
children: []
}
treeNodes.set(item.p,newNode)
}
let parentNode = treeNodes.get(item.p)
parentNode.children.push(childNode)
})
for (let i=0; i<array.length; i++) {
let flag = true
for (let j=0; j<array.length; j++) {
if (array[i].p === array[j].c) {
flag = false
}
}
if (flag) {
rootNode = array[i].p
}
}
return treeNodes.get(rootNode)
}
function removeDuplicate(head) {
var curNode = head
while(curNode) {
var nextNode = curNode.next
while(nextNode) {
if(curNode.value === nextNode.value) {
var preNode = nextNode.pre
var nextNodeNext = nextNode.next
preNode.next = nextNodeNext
nextNodeNext.pre = preNode
} else {
nextNode = nextNode.next
}
}
curNode = curNode.next
}
}
function sizeof(obj) {
let num = 0
for(let key in obj){
if (!obj[key] || typeof obj[key] !== 'object') {
num =
}
num = num + sizeof(obj[key])
}
return num
}