-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathNode.java
50 lines (41 loc) · 1.06 KB
/
Node.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
39
40
41
42
43
44
45
46
47
48
49
50
package com.fishercoder.common.classes;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class Node {
public int val;
public List<Node> children;
public Node() {
this.children = new ArrayList<>();
}
public Node(int val) {
this.val = val;
this.children = new ArrayList<>();
}
public Node(int val, List<Node> children) {
this.val = val;
this.children = children;
}
// todo: implement this method
/*
* return a N-ary tree based on the preorder values
*/
public static Node createNaryTree(List<Integer> preorderValues) {
return null;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Node node = (Node) o;
return val == node.val && Objects.equals(children, node.children);
}
@Override
public int hashCode() {
return Objects.hash(val, children);
}
}