leetcode:Partition List
来源:互联网 发布:网络借钱平台 编辑:程序博客网 时间:2024/05/18 00:28
题目的要求是给出一个链表,和值X,把链表进行重组,前面部分小于x,后面的等于大于x
保持前后面的原始顺序一致
<span style="font-size:18px;">/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode partition(ListNode head, int x) { if(head != null && head.next != null){ ListNode h1 = null, h2 = null; ListNode t1 = null, t2 = null; ListNode pre = head; while(pre != null){ if(pre.val < x){ if(h1 == null){ h1 = pre; t1 = pre; } else{ t1.next = pre; t1 = pre; } } else{ if(h2 == null){ h2 = pre; t2 = pre; } else{ t2.next = pre; t2 = pre; } } pre = pre.next; } if(t1 != null){ t1.next = h2; } else{ h1 = h2; } if(t2 != null) t2.next = null; head = h1; } return head; }}</span>
0 0
- LeetCode: Partition List
- LeetCode Partition List
- LeetCode: Partition List
- [Leetcode] Partition List **
- [Leetcode] Partition List
- [LeetCode] Partition List
- leetcode 81: Partition List
- [Leetcode] Partition List
- leetcode 118: Partition List
- [LeetCode]Partition List
- [leetcode]Partition List
- LeetCode-Partition List
- [leetcode] Partition List
- LeetCode - Partition List
- [LeetCode] Partition List
- LeetCode 86: Partition List
- LeetCode:Partition List
- 【leetcode】Partition List
- pygame安装过程出现找不到videodev.h的错误
- Placeholder for AMDU binaries and using with ASM 10g (Doc ID 553639.1)
- JAVA程序设计(17)----- 制作文件拷贝软件 进程 输入流输出流 NIO 进度条 底层拷贝 多线程
- 模板:(数学:高斯消元法)
- 复制构造函数
- leetcode:Partition List
- 一个java堆溢出的小测试
- 软件工程第二次作业(中国象棋小游戏)
- C/C++内存泄露和野指针的概念
- 为什么默认配置下嵌套的VMware vSphere/ESXi上安装的虚拟机网络连接失败?
- spring 中log4j的配置
- 浅谈安全事件响应
- Coursera台大机器学习基础课程学习笔记1 -- 机器学习定义及PLA算法
- self.navigationItem 与 self.navigationController.navigationItem 的区别