Leetcode:83. Remove Duplicates from Sorted List(JAVA)
来源:互联网 发布:网络暴力赚钱项目 编辑:程序博客网 时间:2024/06/14 20:59
【问题描述】
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
.
维护两个指针,temp,tempnext,如果temp.val == tempnext.val,temp指向tempnext的后一位,同时tempnext后移,否则temp指针后移。
public class Solution { public ListNode deleteDuplicates(ListNode head) { if(head == null) return head; ListNode temp = head, tempnext = head.next; while(tempnext != null){ if(temp.val == tempnext.val ){ temp.next = tempnext.next; tempnext = tempnext.next; }else{ temp = temp.next; } } return head; }}
0 0
- [Leetcode] Remove Duplicates from Sorted List (Java)
- [leetCode][Java] Remove Duplicates from Sorted List
- [LeetCode][Java] Remove Duplicates from Sorted List
- 【leetcode】Remove Duplicates from Sorted List【java】
- leetcode:Remove Duplicates from Sorted List 【Java】
- [LeetCode]Remove Duplicates from Sorted List(Java)
- Remove Duplicates from Sorted List leetcode java
- [LeetCode]83.Remove Duplicates from Sorted List
- [Leetcode] 83. Remove Duplicates from Sorted List
- LeetCode --- 83. Remove Duplicates from Sorted List
- [leetcode] 83.Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- 【leetcode】83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List LeetCode
- leetcode 83. Remove Duplicates from Sorted List
- [LeetCode]83. Remove Duplicates from Sorted List
- 【LeetCode】83. Remove Duplicates from Sorted List
- LeetCode 83. Remove Duplicates from Sorted List
- elasticsearch去重计数(distinct)
- leetcode 每日一题 283. Move Zeroes
- Android多媒体之视频播放器高级开发
- poj2455Secret Milking Machine(二分 + maxflow)
- 关于gcc、glibc和binutils模块之间的关系
- Leetcode:83. Remove Duplicates from Sorted List(JAVA)
- NIO和IO
- Scala 统计一个文件夹下面所有单词出现的次数
- 405, HTTP Status 405 - JSPs only permit GET POST or HEAD.。
- 扩展欧几里得算法
- 从零开始搭建Node.js, Express, Ejs, Mongodb服务器
- VMware上的ubuntu14.04与win7共享文件夹
- Shell Debug
- Jetty实战之 安装 运行 部署