当前位置:网站首页>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;
}
边栏推荐
- Buckle Exercise - 61 Sort by frequency of characters
- Where can I view the version record of WeChat applet submission review history?
- 再有人问你分布式事务,把这篇扔给他
- LeetCode 138. 复制带随机指针的链表
- Introduction to Software Architecture
- gpu-admission 源码分析
- Intel pushes 20220809 CPU microcode update to patch Intel-SA-00657 security vulnerability
- 一文读懂NFT数字藏品为何风靡全球?
- 【机器学习】浅谈正规方程法&梯度下降
- Do self-media monthly income tens of thousands?Several self-media tools that bloggers are using
猜你喜欢
嘉为蓝鲸荣获工信部“数字技术融合创新应用解决方案”
[E-commerce operation] Do you really understand social media marketing (SMM)?
StoneDB Document Bug Hunting Season 1
OPNsense安装配置Zenarmor
LeetCode50天刷题计划(Day 17—— 下一个序列(14.50-16.30)
AutoCAD Map 3D功能之一暴力处理悬挂点(延伸)
Network sockets (UDP and TCP programming)
快手“弃”有赞与微盟“结亲”,电商SaaS行业竞争格局将变?
Intel pushes 20220809 CPU microcode update to patch Intel-SA-00657 security vulnerability
[Go WebSocket] 多房间的聊天室(一)思考篇
随机推荐
不止跑路,拯救误操作rm -rf /*的小伙儿
微信小程序提交审核历史版本记录从哪里查看
因为找不到lombok而找不到符号log
实现内网穿透的最佳解决方案(无实名认证,完全免费)
【LeetCode】640. 求解方程
Article take you understand interrupt the key driver of polling mechanism
jlink and swd interface definition
彩色图和深度图转点云
Interviewer: How are Dao, Service, Controller, Util, and Model divided in the project?
模块九 - 设计电商秒杀系统
[Go WebSocket] 多房间的聊天室(一)思考篇
rider内Mono脚本找不到引用资源
WeChat applet, global variables change in one place and the state in other places also changes.
How to join We Media, learn about these 5 monetization modes, and make your account quickly monetize
力扣练习——58 验证二叉搜索树
Centos7 environment uses Mysql offline installation package to install Mysql5.7
不止跑路,拯救误操作rm -rf /*的小伙儿
零基础想自学软件测试,有没有大佬可以分享下接下来的学习书籍和路线?
中芯CIM国产化项目暂停?上扬软件:未停摆,改为远程开发!
LeetCode 19. 删除链表的倒数第 N 个结点