这是Node结点类
public class Node {
int val;
Node next;
Node(int x) {
val = x;
}
}
这是删除重复结点的方法
public void deleteDuplecate(Node head) {
Node p = head;
while (p != null) {
Node q = p;
while (q.next != null) {
if (p.val != q.next.val) {
q = q.next;
} else {
q.next = q.next.next;
}
}
p = p.next;
}
}