当前位置:网站首页>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;
}
边栏推荐
- 态路小课堂丨如何为CXP光模块选择光纤跳线?
- 力扣练习——62 有效的数独
- std::move()
- Nocalhost - 让云原生时代的开发更高效
- jlink and swd interface definition
- A case of violent parameter tuning in machine learning
- 网络基础(第一节)
- Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
- SMIC CIM localization project suspended?Rising software: not shut down, changed to remote development!
- Module 9 - Designing an e-commerce seckill system
猜你喜欢

一文读懂NFT数字藏品为何风靡全球?

零基础想自学软件测试,有没有大佬可以分享下接下来的学习书籍和路线?

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

SQL优化最强总结 (建议收藏~)

从源码角度分析UUID的实现原理

Module 9 - Designing an e-commerce seckill system

如何使用工程仪器设备在线监测管理系统

L2 applications from a product perspective: why is it a playground?

Nocalhost - 让云原生时代的开发更高效

基于UiAutomator2+PageObject模式开展APP自动化测试实战
随机推荐
LeetCode 146. LRU 缓存
Hangdian Multi-School-Loop-(uncertainty greedy + line segment tree)
微信小程序提交审核历史版本记录从哪里查看
codevs 2370 Small room tree (LCA)
The brave rice rice, does not fear the brush list of 】 list has a ring
ViT结构详解(附pytorch代码)
英特尔推送20220809 CPU微码更新 修补Intel-SA-00657安全漏洞
HDU 4135: Co-prime (the principle of inclusion and exclusion)
学长告诉我,大厂MySQL都是通过SSH连接的
Licking Exercise - 58 Verifying Binary Search Trees
嘉为蓝鲸荣获工信部“数字技术融合创新应用解决方案”
推荐6个自媒体领域,轻松易上手
配置druid数据源「建议收藏」
【机器学习】浅谈正规方程法&梯度下降
10 个 Reduce 常用“奇技淫巧”
十年架构五年生活-09 五年之约如期而至
做自媒体月入几万?博主们都在用的几个自媒体工具
皕杰报表在传参乱码
单目操作符(含原码反码补码转换)
Interviewer: How are Dao, Service, Controller, Util, and Model divided in the project?