-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListDmeo.java
More file actions
49 lines (35 loc) · 968 Bytes
/
Copy pathLinkedListDmeo.java
File metadata and controls
49 lines (35 loc) · 968 Bytes
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
package datastructers;
import java.util.HashSet;
class ListNode{
int val;
ListNode next;
ListNode(int val)
{
this.val = val;
this.next = null;
}
}
public class LinkedListDmeo {
public static void main(String[] args) {
ListNode n1 = new ListNode(1);
ListNode n2 = new ListNode(2);
ListNode n3 = new ListNode(3);
ListNode n4 = new ListNode(2);
ListNode n5 = new ListNode(3);
ListNode n6 = new ListNode(6);
n1.next = n2;
n2.next = n3;
n3.next = n4;
n4.next = n5;
n5.next = n6;
ListNode curr = n1;
HashSet<Integer> set = new HashSet<Integer>();
while (curr !=null){
set.add(curr.val);
curr = curr.next;
}
System.out.println(set.size());
for (Integer node: set) {
}
}
}