当前位置:网站首页>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;
}
}边栏推荐
- leetcode122. Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II(简单)
- AI全流程开发难题破解之钥
- 转:idea中language level设置
- jsonArray中按某字段排序
- [Point Cloud] M3DeTR: Multi-representation, Multi-scale, Mutual-relation 3D Object Detection with Transformers
- GBASE 8s 数据索引
- 在Ferora35中安装oracle-database-xe-21c
- 【R语言】【2】绘图base和lattice和ggplot2库
- HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
- 【LeetCode】36、有效的数独
猜你喜欢
随机推荐
防火墙——SNAT和DNAT策略的原理及应用、防火墙规则的备份和还原
Leetcode 705.设计哈希集合
The world is on fire, Google servers have crashed
GBASE 8s 数据索引
GBASE 8s 自定义存储过程和函数示例
二叉树的操作集:(二叉树的定义,遍历)
Advanced Mathematics (Seventh Edition) Tongji University Exercises 3-7 Individual Answers
十一、HikariCP源码分析之HouseKeeper
viewpager fragment data refresh
【ORM框架:Sequelize的查询】
leetcode122. Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II(简单)
AI全流程开发难题破解之钥
php反序列化结构知识点实例分析
获取七牛云地址文件保存到本地
专利说明书怎么写?
JZ18 删除链表的节点
Get the Qiniu cloud address file and save it locally
新手如何写专利?
ict的终极模式 是软件研发
03-树2 List Leaves








