当前位置:网站首页>Remove duplicates from sorted list II of leetcode topic resolution
Remove duplicates from sorted list II of leetcode topic resolution
2022-06-23 06:14:00 【ruochen】
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
For example,
Given 1->2->3->3->4->4->5, return 1->2->5.
Given 1->1->1->2->3, return 2->3.
public ListNode deleteDuplicates(ListNode head) {
if (head == null) {
return null;
}
if (head.next == null) {
return head;
}
int val = head.val;
ListNode node = head;
boolean killme = false;
while (node.next != null && node.next.val == val) {
node = node.next;
killme = true;
}
if (killme) {
head = deleteDuplicates(node.next);
} else {
head.next = deleteDuplicates(node.next);
}
return head;
}边栏推荐
- Wireshark TS | video app cannot play
- 【DaVinci Developer专题】-42-如何生成APP SWC的Template和Header文件
- Efficient office of fintech (I): automatic generation of trust plan specification
- Alibaba cloud ack one and ACK cloud native AI suite have been newly released to meet the needs of the end of the computing era
- Kotlin collaboration +retro most elegant network request use
- 金融科技之高效办公(一):自动生成信托计划说明书
- Real MySQL interview questions (XXVI) -- didi 2020 written examination questions
- Infotnews | which Postcard will you receive from the universe?
- Given a node of a binary tree, return the successor node of the node
- 100-300 cases of single chip microcomputer program (detailed explanation of notes)
猜你喜欢

Summary of ant usage (I): using ant to automatically package apk

Redis 哨兵

Real MySQL interview questions (25) -- common group comparison scenarios

Day_12 传智健康项目-JasperReports

Learning Tai Chi Maker - esp8226 (11) distribution network with WiFi manager Library

金融科技之高效办公(一):自动生成信托计划说明书

Explicability of counter attack based on optimal transmission theory

Runc symbolic link mount and container escape vulnerability alert (cve-2021-30465)

mysql读已提交和可重复度区别

Ant Usage Summary (II): description of related commands
随机推荐
Pyinstaller package exe setting icon is not displayed
Implementation of linear list linked list structure
Real MySQL interview questions (XXVI) -- didi 2020 written examination questions
WordPress aawp 3.16 cross site scripting
[cocos2d-x] screenshot sharing function
exe闪退的原因查找方法
Centos7 installation of postgresql8.2.15 and creation of stored procedures
Pat class B 1020 Moon Cake
Explicability of counter attack based on optimal transmission theory
Radar canvas
学习太极创客 — ESP8226 (十一)用 WiFiManager 库配网
又到半年总结时,IT人只想躺平
The difference between SaaS software and traditional software delivery mode
Pyinstaller sklearn报错的问题
How to add libraries for Arduino ide installation
jvm-05.垃圾回收
Adnroid activity screenshot save display to album view display picture animation disappear
【Leetcode】431. Encode N-ary Tree to Binary Tree(困难)
Machine learning 3-ridge regression, Lasso, variable selection technique
Kotlin collaboration +retro most elegant network request use