【LeetCode从零单排】No83 Remove Duplicates from Sorted List
生活随笔
收集整理的这篇文章主要介绍了
【LeetCode从零单排】No83 Remove Duplicates from Sorted List
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题目
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.
代码
public static ListNode deleteDuplicates(ListNode head) {if (head==null || head.next==null) return head; ListNode first = head;ListNode second=head.next;while(second!=null){if(first.val==second.val){second=second.next;first.next=second;} else{first=first.next;second=first.next; }}return head;}代码下载:https://github.com/jimenbian/GarvinLeetCode
/********************************
* 本文来自博客 “李博Garvin“
* 转载请标明出处:http://blog.csdn.net/buptgshengod
******************************************/
《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读
总结
以上是生活随笔为你收集整理的【LeetCode从零单排】No83 Remove Duplicates from Sorted List的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 【LeetCode从零单排】No88.M
- 下一篇: 【LeetCode从零单排】No100