链表分割
来源:互联网 发布:网络金融诈骗判多少年 编辑:程序博客网 时间:2024/06/06 17:26
public class Partition { public ListNode partition(ListNode pHead, int x) { // write code here //把总的链表拆成连个独立的链表 ListNode lowHead = null,highHead =null,curLow = null,curHigh=null,cur; while(pHead!=null){ cur = pHead; pHead = pHead.next; cur.next = null; if(cur.val < x){ if(lowHead == null) lowHead = cur; else curLow .next = cur; curLow = cur; }else{ if(highHead == null) highHead = cur; else curHigh .next = cur; curHigh = cur; } } //链接两个链表 if(curLow !=null) curLow.next = highHead;return curLow == null? highHead:lowHead;}}
题目描述
编写代码,以给定值x为基准将链表分割成两部分,所有小于x的结点排在大于或等于x的结点之前
给定一个链表的头指针 ListNode* pHead,请返回重新排列后的链表的头指针。注意:分割以后保持原来的数据顺序不变。
阅读全文
0 0
- 分割单向链表
- 分割链表
- 链表分割
- 链表分割
- 链表分割(Java)
- 链表分割
- 牛客网 | 链表分割
- 链表分割
- 链表分割
- 链表分割
- 链表分割问题
- 链表分割
- 链表分割
- 链表分割
- 链表分割
- 链表分割
- [牛客]链表分割
- 链表分割
- Android Studio 快捷键,配置自定义键映射
- 面向对象设计原则概述
- Bootstrap Table使用整理(二)
- Add zip into GIT Bash on Windows
- 设计模式学习_javascript_观察者模式
- 链表分割
- 欢迎使用CSDN-markdown编辑器
- 人脸属性预测之书山有路
- 小白谈谈对JS原型链的理解
- hibernate查询
- 关于studio中的Run/Debug Configurations不能运行的问题及解决方案
- 欢迎使用CSDN-markdown编辑器
- 每日学习巩固知识,下班回顾总结
- Fiddler常用功能介绍