-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeNode.java
38 lines (30 loc) · 1 KB
/
TreeNode.java
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
package com.company.FunWithListsTreesEdition;
class TreeNode {
public TreeNode left;
public TreeNode right;
public int value;
TreeNode(int value, TreeNode left, TreeNode right) {
this.value = value;
this.left = left;
this.right = right;
}
TreeNode(int value) {
this(value, null, null);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TreeNode treeNode = (TreeNode) o;
if (value != treeNode.value) return false;
if (left != null ? !left.equals(treeNode.left) : treeNode.left != null) return false;
return right != null ? right.equals(treeNode.right) : treeNode.right == null;
}
@Override
public int hashCode() {
int result = left != null ? left.hashCode() : 0;
result = 31 * result + (right != null ? right.hashCode() : 0);
result = 31 * result + value;
return result;
}
}