-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathisTreeSymmetric.js
More file actions
59 lines (55 loc) · 1.61 KB
/
Copy pathisTreeSymmetric.js
File metadata and controls
59 lines (55 loc) · 1.61 KB
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
"use strict"
/*****************************************************************************
* File Name: isTreeSymmetric.js
* Project: HTML5
* Author: JustMeet - Dazhi Tang
*
* Discribe:
*
* This material contains, and is a part of a computer software program
* which is, proprietary and confidential information owned by
* JustMeet Technology.
* The program, including this material, may not be duplicated, disclosed
* or reproduced in whole or in part for any purpose without the express
* written authorization of Verizon Corporate Technology. All authorized
* reproductions must be marked with this legend.
* All rights reserved.
*****************************************************************************/
//
// Definition for binary tree:
// function Tree(x) {
// this.value = x;
// this.left = null;
// this.right = null;
// }
function isTreeSymmetric(t) {
if(!t) return true;
var t1 = t.left;
var t2 = t.right;
var unvisited1 = []//.push(t1)
var unvisited2 = []//.push(t2)
unvisited1.push(t1)
unvisited2.push(t2)
// console.log(unvisited1.length)
while(unvisited1.length){
root1 = unvisited1.shift();
root2 = unvisited2.shift();
if(root1==null && root2 == null){
continue
}else if (root1==null || root2==null){
console.log('root2')
return false
}else{
console.log(root1.value)
console.log(root2.value)
if (root1.value != root2.value ){
return false
}
unvisited1.push(root1.left)
unvisited1.push(root1.right)
unvisited2.push(root2.right)
unvisited2.push(root2.left)
}
}
return true
}