partition-list Java code
来源:互联网 发布:editplus php代码提示 编辑:程序博客网 时间:2024/05/20 19:17
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
You should preserve the original relative order of the nodes in each of the two partitions.
For example,
Given1->4->3->2->5->2and x = 3,
return1->2->2->4->3->5.
/** * 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) return null; ListNode dummy1=new ListNode(0); ListNode dummy2=new ListNode(0); ListNode curr1=dummy1; ListNode curr2=dummy2; while(head!=null){ if(head.val<x){ curr1.next=head; curr1=curr1.next; }else{ curr2.next=head; curr2=curr2.next; } head=head.next; } curr2.next=null; curr1.next=dummy2.next; return dummy1.next; }}
阅读全文
0 0
- partition-list Java code
- CODE 47: Partition List
- [leet code] Partition List
- [Leetcode] Partition List (Java)
- Partition List (Java)
- [LeetCode][Java] Partition List
- leetcode:Partition List 【Java】
- LeetCode-JAVA-Partition List
- Partition List leetcode java
- [leet code] Partition List Pow(x, n)
- leetcode 日经贴,Cpp code -Partition List
- [LeetCode] 86. Partition List java
- sort-list java code
- reorder-list Java code
- LeetCode 86(Partition List)java
- [leetcode]86. Partition List@Java解题报告
- Partition List
- Partition List
- 【Linux内核】timer子系统
- Java POI 导出EXCEL
- spring的事务有几种方式,谈谈spring事务的隔离级别和传播行为
- ③看视频NDK学习之C常用函数
- iOS 打电话弹出太慢
- partition-list Java code
- 二叉树删除节点
- Leetcode477. 计算海明距离
- android 3.0 提示找不到@android:windowEnterAnimation
- C-Free编译器[C/C++集成开发环境]
- Lua-基础知识细节
- 归并排序和快速排序总结
- 如何双击运行可执行jar包
- 起点...