1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
}