LeetCode (Remove Duplicates from Sorted List)
来源:互联网 发布:看淘宝服务器的时间 编辑:程序博客网 时间:2024/05/21 21:29
Problem:
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
.
/** * 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) { if(!head || !head->next) return head; if(head->val == head->next->val) return deleteDuplicates(head->next); else{ head->next = deleteDuplicates(head->next); return head; } }};
阅读全文
0 0
- Remove Duplicates from Sorted List :from LeetCode
- Leetcode - List - Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- [leetcode][list] Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List
- [Leetcode] Remove Duplicates from Sorted List II
- LeetCode: Remove Duplicates from Sorted List
- LeetCode: Remove Duplicates from Sorted List II
- [Leetcode] Remove Duplicates from Sorted List II
- leetcode 37: Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List II
- [LeetCode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List
- [leetcode] Remove Duplicates from Sorted List II
- [LeetCode]Remove Duplicates from Sorted List
- CSS的优化与性能提高
- Python学习之异常处理详解
- 在线云评测系统日志三
- SDUVJ开发实录(四):Problem与ProblemList显示
- Java8 新特性学习总结
- LeetCode (Remove Duplicates from Sorted List)
- 苹果App部署HTTPS进行在线下载安装--基于能找到苹果设备id
- 89. Gray Code
- java中length,length(),size()区别
- 栈的作用,实现加减乘除的功能
- IDEA下新建一个Web Project并配置tomcat
- (60)组件之形状组件
- Apue第一章
- 神奇数