LeetCode p83 Remove Duplicates from Sorted List 题解 1.题目: 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. 题意: 去掉一个有序链表中重复的数。 2.解题思路: 见代码 3.代码 [title] [] [url] [link text] 12345678910111213141516171819202122232425 * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class { public ListNode deleteDuplicates(ListNode head) { ListNode ans = head; if (head == null) return null; while (head != null && head.next != null) { if (head.next.val == head.val) { head.next = head.next.next; continue; } head = head.next; } return ans; }} 4.一些总结: 赞微海报分享
近期评论