当前位置:网站首页>JZ76 删除链表中重复的结点
JZ76 删除链表中重复的结点
2022-07-29 21:49:00 【syc596】
JZ76 删除链表中重复的结点
删除链表中重复的结点_牛客题霸_牛客网 (nowcoder.com)
// import java.util.*;
// public class Solution {
// public ListNode deleteDuplication(ListNode head) {
// if(head==null){
// return null;
// }
// ListNode vhead=new ListNode(-1);
// vhead.next=head;
// ListNode cur=vhead;
// while(cur.next!=null&&cur.next.next!=null){
// if(cur.next.val==cur.next.next.val){
// int tmp=cur.next.val;
// while(cur.next!=null&&cur.next.val==tmp){
// cur.next=cur.next.next;
// }
// }else{
// cur=cur.next;
// }
// }
// return vhead.next;
// }
// }
//11
//map
import java.util.*;
public class Solution {
public ListNode deleteDuplication(ListNode head) {
if(head==null){
return null;
}
Map<Integer,Integer> map=new HashMap<>();
ListNode cur=head;
while(cur!=null){
if(map.containsKey(cur.val)){
map.put(cur.val,map.get(cur.val)+1);
}else{
map.put(cur.val,1);
}
cur=cur.next;
}
ListNode vhead=new ListNode(-1);
vhead.next=head;
cur=vhead;
while(cur.next!=null){
if(map.get(cur.next.val)!=1){
cur.next=cur.next.next;
}else{
cur=cur.next;
}
}
return vhead.next;
}
}边栏推荐
- 啊?现在初级测试招聘都要求会自动化了?
- GBASE 8s 数据索引
- leetcode 890. Find and Replace Pattern(查找和替换pattern)
- GBASE 8s 自动删除正在被使用的数据库
- 外文论文的格式规范要求有哪些?
- 新库上线 | CnOpenData国际货运代理信息数据
- One of the uses of linkedlist: Get the address of the structure variable through the address of the structure member
- Sorry, it's hard for you to earn middle-aged money
- 六、HikariConfig配置解析
- [Point Cloud] M3DeTR: Multi-representation, Multi-scale, Mutual-relation 3D Object Detection with Transformers
猜你喜欢
随机推荐
【点云】M3DeTR: Multi-representation, Multi-scale, Mutual-relation 3D Object Detection with Transformers
全系都更换带T四缸,安全、舒适一个不落
利用go通道channel实现互斥锁
Verilog 加法器设计
【R语言】【2】绘图base和lattice和ggplot2库
五、HikariCP源码分析之初始化分析二
chrome集成沙拉查词
程序员「小镇做题」出身,月薪是父母半年收入 ……
24-hour London gold chart analysis
给pdf添加已作废标识
【CVPR2022】A Unified Query-based Paradigm for Point Cloud Understanding
官宣!苏州吴江开发区上线电子劳动合同平台
撰写英文文献有哪些技巧?
对不起,你很难赚到中年人的钱
数据安全建设
聊聊阻容降压原理 和 实际使用的电路
lambda表达式
leetcode122. Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II(简单)
linux使用脚本安装redis
JZ18 删除链表的节点









