83. Remove Duplicates from Sorted List

 1 class Solution {
 2     public ListNode deleteDuplicates(ListNode head) {
 3         if(head == null || head.next == null) return head;
 4         ListNode node1 = head;
 5         ListNode node2 = head.next;
 6         while(node2 != null) {
 7             if(node2.val == node1.val) {
 8                 node2 = node2.next;
 9             }else {
10                 node1.next = node2;
11                 node1 = node2;
12                 node2 = node2.next;
13             }
14         }
15         node1.next = null;
16         return head;
17         
18     }
19 }

 

posted @ 2018-09-16 10:06  jasoncool1  阅读(116)  评论(0编辑  收藏  举报