1. 程式人生 > >LC_83. Remove Duplicates from Sorted List

LC_83. Remove Duplicates from Sorted List

val 1-1 改變 || rem move 什麽 lis while

https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/
Given a sorted linked list, delete all duplicates such that each element appear only once.

For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.

 1 public ListNode deleteDuplicates(ListNode head) {
2 if (head == null || head.next == null) return head ; 3 ListNode curr = head ; 4 /* 5 * 重點體會跳過去是什麽意思 CURR =HEAD 然後改變 CURR.NEXT HEAD.next 也是會被變化的 6 * */ 7 /* 8 * 1-1-1-1-2-2-3 9 * c---> 10 * ----> 11 * ------->
12 * c 13 * h-------> 14 * */ 15 while(curr.next!=null){ 16 if (curr.val == curr.next.val){ 17 curr.next = curr.next.next ; 18 } else { 19 curr = curr.next ; 20 } 21 } 22 return
head ; 23 }

LC_83. Remove Duplicates from Sorted List