83. Remove Duplicates from Sorted List
来源:互联网 发布:桌面图标软件 编辑:程序博客网 时间:2024/06/10 00:21
Given a sorted linked list, delete all duplicates such that each element appear only once.
这个题目采用了两种方法,一种递归,一种循环,其实原理都差不多。就是一个个找下一个的值是否和当前节点的值相同,若相同则删除,若不同,则继续检查下一个节点。
//方法一var deleteDuplicates = function(head) { if(head==null || head.next==null)return head; if(head.val==head.next.val){ var temp=head.next.next; //delete head.next; head.next=temp; deleteDuplicates(head); } else deleteDuplicates(head.next); return head;}// 方法二var deleteDuplicates = function(head) { var temp=new ListNode(head.val); temp=head; while(temp && temp.next){ if(temp.next.val==temp.val){ var de=temp.next.next; delete temp.next; temp.next=de; } else temp=temp.next; } return head;}
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
- Java集合框架面试问题集锦
- Linux系统结构 详解
- python人脸识别
- Android 6.0 运行时权限封装
- android基础知识---Mean菜单管理
- 83. Remove Duplicates from Sorted List
- tnsname和listener
- 存储用户信息案例
- linux系统安装JDk
- c++学习进阶之路
- java day7
- sublime text 的小细节设置,让你的代码更优美
- EasyUI之日期输入框dateBox
- win8系统怎么装会win7系统