MCPcopy
hub / github.com/careercup/ctci / deleteDupsA

Method deleteDupsA

java/Chapter 2/Question2_1/Question.java:10–22  ·  view source on GitHub ↗
(LinkedListNode n)

Source from the content-addressed store, hash-verified

8
9public class Question {
10 public static void deleteDupsA(LinkedListNode n) {
11 HashSet<Integer> set = new HashSet<Integer>();
12 LinkedListNode previous = null;
13 while (n != null) {
14 if (set.contains(n.data)) {
15 previous.next = n.next;
16 } else {
17 set.add(n.data);
18 previous = n;
19 }
20 n = n.next;
21 }
22 }
23
24 public static void deleteDupsC(LinkedListNode head) {
25 if (head == null) return;

Callers 1

mainMethod · 0.95

Calls 2

containsMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected