LeetCode-83-Remove Duplicates from Sorted List(链表)-Medium
来源:互联网 发布:出入无时 莫知其乡 编辑:程序博客网 时间:2024/06/17 02:29
题意理解:
删除链表中的重复项;
题目分析:
使用双指针分别记录当前位置和先前位置,然后比较当前值是否与先前值重复,进而进行删除重复项操作;
解题代码:
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode deleteDuplicates(ListNode head) { ListNode curP=head; ListNode preP=null; int preVal=0; while(curP!=null){ if(curP==head){ preVal=curP.val; preP=curP; curP=curP.next; continue; } if(curP.val==preVal){ preP.next=curP.next; curP=curP.next; }else{ preP=curP; preVal=curP.val; curP=curP.next; } } return head; }}
0 0
- LeetCode-83-Remove Duplicates from Sorted List(链表)-Medium
- LeetCode-82-Remove Duplicates from Sorted List II(链表)-Medium
- [Leetcode 82, Medium] Remove Duplicates from Sorted List II
- Leetcode 82. Remove Duplicates from Sorted List II (Medium) (cpp)
- 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
- 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
- Leetcode #83 Remove Duplicates from Sorted List
- leetcode 83: Remove Duplicates from Sorted List
- Observable
- 贪心 1006
- ACM-problem A
- Single
- 数据结构课设 旅游规划(dijkstra扩展)
- LeetCode-83-Remove Duplicates from Sorted List(链表)-Medium
- Subject
- xampp win32下配置mail() 发邮件
- 调度器 Scheduler
- 贪心1007
- 全部操作符列表
- 168. Excel Sheet Column Title
- SPOJ 1676 GEN - Text Generatord
- 操作符分类