当前位置:网站首页>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;
}
边栏推荐
- 面试官:你们是如何保证接口的幂等性?
- A case of violent parameter tuning in machine learning
- Nocalhost - 让云原生时代的开发更高效
- 孩子自律性不够?猿辅导:计划表要注意“留白”给孩子更多掌控感
- If someone asks you about distributed transactions again, throw this to him
- 项目部署、
- 学长告诉我,大厂MySQL都是通过SSH连接的
- HDU 4135: Co-prime (the principle of inclusion and exclusion)
- 因为找不到lombok而找不到符号log
- VSCode远程连接服务器报错:Could not establish connection to “xxxxxx”的可能错误原因及解决
猜你喜欢

Nocalhost - Making development more efficient in the cloud-native era

Network sockets (UDP and TCP programming)

rider内Mono脚本找不到引用资源

模块九 - 设计电商秒杀系统

态路小课堂丨如何为CXP光模块选择光纤跳线?

即时零售业态下如何实现自动做账?

常量及数据类型你还记得多少?

机器学习之暴力调参案例
![[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list](/img/87/7ac0307de54f2defe8f72c554745cd.png)
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list

Module 9 - Designing an e-commerce seckill system
随机推荐
自媒体爆款标题怎么写?手把手教你写热门标题
力扣练习——62 有效的数独
Redis常用命令
LeetCode 138. Copy a linked list with random pointers
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list
LeetCode50天刷题计划(Day 16—— 两两交换链表中的节点(9.10-10.30)
一文读懂NFT数字藏品为何风靡全球?
【TypeScript】接口类型与类型别名:这两者的用法与区别分别是什么?
不止跑路,拯救误操作rm -rf /*的小伙儿
LeetCode 19. Delete the Nth last node of the linked list
SMIC CIM localization project suspended?Rising software: not shut down, changed to remote development!
If someone asks you about distributed transactions again, throw this to him
StoneDB Document Bug Hunting Season 1
Analysis of the name matching process between the LCD driver and the device (Tiny4412)
LeetCode 369. Plus One Linked List(链表加1)
从源码角度分析UUID的实现原理
L2 applications from a product perspective: why is it a playground?
Analysis of the implementation principle of UUID from the perspective of source code
力扣练习——64 最长和谐子序列
LeetCode 24. 两两交换链表中的节点