LeetCode83 Remove Duplicates from Sorted List
来源:互联网 发布:淘宝商城一年费用多少 编辑:程序博客网 时间:2024/06/03 23:46
LeetCode83 Remove Duplicates from Sorted List
问题链接 LeetCode83
问题描述
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 ListNode deleteDuplicates(ListNode head) { if(head==null){ return head; } ListNode myHead = new ListNode(-1); myHead.next = head; while(head.next!=null){ if(head.val==head.next.val){ head.next = head.next.next; }else{ head = head.next; } } return myHead.next;}// class ListNode {// int val;// ListNode next;// ListNode(int x) { val = x; }// }
LeetCode学习笔记持续更新
GitHub地址 https://github.com/yanqinghe/leetcode
CSDN博客地址 http://blog.csdn.net/yanqinghe123/article/category/7176678
阅读全文
0 0
- LeetCode83:Remove Duplicates from Sorted List
- leetcode83 Remove Duplicates from Sorted List
- leetcode83:Remove Duplicates from Sorted List
- leetcode83: Remove Duplicates from Sorted List
- leetcode83. Remove Duplicates from Sorted List
- leetcode83~Remove Duplicates from Sorted List
- LeetCode83. Remove Duplicates from Sorted List
- LeetCode83. Remove Duplicates from Sorted List
- LeetCode83 Remove Duplicates from Sorted List
- LeetCode83——Remove Duplicates from Sorted List
- LeetCode83之Remove Duplicates from Sorted List的Java题解
- leetcode83---Remove Duplicates from Sorted List(删除重复元素)
- LeetCode83——Remove Duplicates from Sorted List
- leetcode83.Remove Duplicates from Sorted Lists
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove Duplicates from Sorted List
- Remove duplicates from sorted list
- C语言 数据输入/输出函数
- java学习结构图
- PAT --- 1012. 数字分类 (20)
- 电脑环境变量的配置
- 1006. 换个格式输出整数 (15)
- LeetCode83 Remove Duplicates from Sorted List
- java中"+"的用法
- [POJ 1275] Cashier Employment 差分约束系统
- node作为中间层进行前后端分离
- usaco
- Java编程思想-6
- eclipse tomcat 设置
- equals 和 == 的区别
- Java-使用beanUtils操作javabean(学习笔记)