当前位置:网站首页>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;
}
边栏推荐
- How many constants and data types do you remember?
- Since the media hot style title how to write?Taught you how to write the title
- LeetCode 369. Plus One Linked List(链表加1)
- 中芯CIM国产化项目暂停?上扬软件:未停摆,改为远程开发!
- 再有人问你分布式事务,把这篇扔给他
- StoneDB Document Bug Hunting Season 1
- Network sockets (UDP and TCP programming)
- 网络基础(第一节)
- LeetCode 138. Copy a linked list with random pointers
- 力扣练习——62 有效的数独
猜你喜欢
一文读懂NFT数字藏品为何风靡全球?
Since the media hot style title how to write?Taught you how to write the title
零基础想自学软件测试,有没有大佬可以分享下接下来的学习书籍和路线?
If someone asks you about distributed transactions again, throw this to him
How to join We Media, learn about these 5 monetization modes, and make your account quickly monetize
ViT结构详解(附pytorch代码)
建校仅11年就入选“双一流” ,这所高校是凭什么做到的?
石墨文档打开文档时快速定位到上次写的位置
Do self-media monthly income tens of thousands?Several self-media tools that bloggers are using
即时零售业态下如何实现自动做账?
随机推荐
WeChat applet, global variables change in one place and the state in other places also changes.
Network sockets (UDP and TCP programming)
Analysis of the name matching process between the LCD driver and the device (Tiny4412)
三星计划2023年开始在越南生产半导体零部件
LeetCode 92. 反转链表 II
关于振弦采集模块及采集仪振弦频率值准确率的问题
HDU 6040 Hints of sd0061 (技巧)
配置druid数据源「建议收藏」
ssm框架搭建过程[通俗易懂]
十年架构五年生活-09 五年之约如期而至
Clicking Exercise - 64 Longest Harmonic Subsequences
LeetCode 445. 两数相加 II
英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞
皕杰报表在传参乱码
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list
使用哈工大LTP测试分词并且增加自定义字典
gpu-admission 源码分析
10 个 Reduce 常用“奇技淫巧”
leetcode 823. Binary Trees With Factors(因子二叉树)
因为找不到lombok而找不到符号log