Created
September 2, 2015 17:16
-
-
Save cxtadment/6e9eea7842ee3130dc76 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Definition for ListNode | |
| * public class ListNode { | |
| * int val; | |
| * ListNode next; | |
| * ListNode(int x) { | |
| * val = x; | |
| * next = null; | |
| * } | |
| * } | |
| */ | |
| public class Solution { | |
| /** | |
| * @param ListNode head is the head of the linked list | |
| * @return: ListNode head of linked list | |
| */ | |
| public static ListNode deleteDuplicates(ListNode head) { | |
| // write your code here | |
| if (head == null || head.next == null) { | |
| return head; | |
| } | |
| ListNode pre = head; | |
| ListNode curr = head.next; | |
| while (curr != null) { | |
| if (pre.val == curr.val) { | |
| curr = curr.next; | |
| } else { | |
| pre.next = curr; | |
| pre = pre.next; | |
| } | |
| } | |
| pre.next = null; | |
| return head; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment