-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution_deleteDuplicates.java
47 lines (44 loc) · 1.05 KB
/
Solution_deleteDuplicates.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
package com.bupt.kcrosswind.Leetcode;
import java.util.Arrays;
public class Solution_deleteDuplicates {
public static ListNode deleteDuplicates(ListNode head) {
if (head == null) {
return head;
}
ListNode temp = new ListNode(0);
temp.next = head;
ListNode pre = temp;
ListNode cursor = head;
while (cursor != null && cursor.next != null) {
if (cursor == cursor.next) {
while (cursor == cursor.next) {
cursor = cursor.next;
}
pre.next = cursor.next;
cursor = cursor.next;
System.out.println("hehe");
} else {
System.out.println("hehe");
pre = pre.next;
cursor = cursor.next;
}
}
return temp.next;
}
public static void main(String[] args) {
ListNode head = new ListNode(1);
ListNode head1 = new ListNode(1);
head.next = head1;
ListNode result = deleteDuplicates(head);
while (result != null) {
System.out.println(result.val);
result = result.next;
}
int[] A = { 1, 2, 3 };
int[] B = { 4, 5, 6 };
A = Arrays.copyOf(B, 2);
for (int i : A) {
System.out.println(i);
}
}
}