83. Remove Duplicates from Sorted List
来源:互联网 发布:蒙古灭宋 知乎 编辑:程序博客网 时间:2024/06/06 12:39
Problem:
iven 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.
题意是删除链表中每个节点val相等的节点。没什么算法好说,就操作指针就好。
Code:
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* deleteDuplicates(ListNode* head) { ListNode *lastNode = head; ListNode *result = head; while (head) { if (head -> val == lastNode -> val) { lastNode -> next = head -> next; head = head -> next; continue; } head = head -> next; lastNode = lastNode -> next; } return result; }};
阅读全文
0 0
- [LeetCode]83.Remove Duplicates from Sorted List
- 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 83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 【leetcode】83. Remove Duplicates from Sorted List
- 83. Remove Duplicates from Sorted List
- 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
- 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
- GNU, Free Software and Open Source 自由软件与开源软件
- 切换选项卡
- git工作方式简介
- 百练OJ:2764:数根
- 异常处理
- 83. Remove Duplicates from Sorted List
- LWC 49:676. Implement Magic Dictionary
- View的事件分发机制源码分析
- maven创建项目后出现“One or more constraints have not been satisfied、Dynamic Web Module 3.0 requires ”错误解决办法
- Java之CyclicBarrier使用
- 搭建hadoop伪分布式
- 短信接口(阿里大于)
- 多表查询练习
- Java之CountDownLatch使用