还是linkedlist的题目
1---2---2---3---4---4----5 sort list 去重
使得result为:1---2---3---4---5
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head==null) return head;
ListNode start = head;
while(head!=null){
if(start.next==null) break;
if(start.val==start.next.val){
start.next=start.next.next;
}
else{
start = start.next;//把start移动,向后继续判断
}
}
return head;
}
}
这一次学到的是,用一个start来作为移动承接的node