当前位置:网站首页>LeetCode 86. Delimited Linked List
LeetCode 86. Delimited Linked List
2022-08-10 11:57:00 【Mizuna pen】
原题网址:https://leetcode.cn/problems/partition-list/submissions/
给一个链表,和一个定值;Requests less than this fixed value to be ranked first and the rest to be ranked together;
用两个链表;A node that holds less than a fixed value,One holds the rest of the linked list;
public ListNode partition(ListNode head, int x) {
// Use two linked lists to store less than onexone of the values holds the rest
ListNode lessNode = new ListNode(-1);
ListNode less = lessNode;
ListNode moreNode = new ListNode(-1);
ListNode more = moreNode;
ListNode cur = head;
while(cur != null) {
if(cur.val < x) {
ListNode temp = cur;
less.next = cur;
less = less.next;
cur = cur.next;
temp.next = null;
} else {
ListNode temp = cur;
more.next = cur;
more = more.next;
cur = cur.next;
temp.next = null;
}
}
less.next = moreNode.next;
return lessNode.next;
}
边栏推荐
- 个推数据资产管理经验 | 教你打造数据质量心电图,智能检测数据“心跳”异常
- 迈矽科推出高性能77GHz毫米波雷达芯片,尚未量产就已获数万颗订单
- [E-commerce operation] Do you really understand social media marketing (SMM)?
- 石墨文档打开文档时快速定位到上次写的位置
- jlink 与 swd 接口定义
- LeetCode 138. Copy a linked list with random pointers
- 【LeetCode】640. 求解方程
- 微信小程序,全局变量一个地方改变了其他地方的状态也跟着改变。
- [Go WebSocket] 多房间的聊天室(一)思考篇
- AutoCAD Map 3D功能之一暴力处理悬挂点(延伸)
猜你喜欢
推荐6个自媒体领域,轻松易上手
Article take you understand interrupt the key driver of polling mechanism
英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞
关于振弦采集模块及采集仪振弦频率值准确率的问题
StoneDB 文档捉虫活动第一季
StoneDB Document Bug Hunting Season 1
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list
rider内Mono脚本找不到引用资源
网络套接字(UDP和TCP编程)
为什么Redis很快
随机推荐
Stroke Practice - 62 Valid Sudokus
Go 事,Gopher 要学的数字类型,变量,常量,运算符 ,第2篇
gpu-admission 源码分析
配置swagger
【LeetCode】640. 求解方程
VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions
Module 9 - Designing an e-commerce seckill system
中芯CIM国产化项目暂停?上扬软件:未停摆,改为远程开发!
实现内网穿透的最佳解决方案(无实名认证,完全免费)
Licking Exercise - 63 Find all anagrams in a string
从源码角度分析UUID的实现原理
std::move()
【小程序 | 启航篇】一文打通任督二脉
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list
LeetCode50天刷题计划(Day 19—— 在排序数组中查找元素的第一个和最后一个位置(9.10-10.40)
Buckle exercise - rectangular area does not exceed the maximum value of K and (hard)
Licking Exercise - 60 Maximum key-value sum of binary search subtrees
基于UiAutomator2+PageObject模式开展APP自动化测试实战
暑期总结4
使用.NET简单实现一个Redis的高性能克隆版(六)