首页 > 其他 > 详细

[leetcode]83. Remove Duplicates from Sorted List有序链表去重

时间:2018-06-26 10:38:52      阅读:173      评论:0      收藏:0      [点我收藏+]

Given a sorted linked list, delete all duplicates such that each element appear only once.

Example 1:

Input: 1->1->2
Output: 1->2

Example 2:

Input: 1->1->2->3->3
Output: 1->2->3

 

题意:

有序链表去重

 

思路:

 

技术分享图片

 

技术分享图片

 

 

代码:

 1 class Solution {
 2     public ListNode deleteDuplicates(ListNode head) {
 3         if(head == null) return head;       
 4         ListNode cur = head;      
 5         while(cur.next != null){
 6             if(cur.val == cur.next.val){
 7                 cur.next = cur.next.next;
 8             }else{
 9                 cur = cur.next;
10             }
11         }
12         return head;
13     }
14 }

 

[leetcode]83. Remove Duplicates from Sorted List有序链表去重

原文:https://www.cnblogs.com/liuliu5151/p/9227166.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!