leetcode Partition List
来源:互联网 发布:js数组 编辑:程序博客网 时间:2024/05/16 15:06
题目链接
package newcoder;class ListNode { int val; ListNode next; ListNode(int x) { val = x; }}public class Solution { public static void main(String args[]) { Solution obj=new Solution(); ListNode h=new ListNode(2); h.next=new ListNode(1); obj.partition(h, 1); } public ListNode partition(ListNode head, int x) { if(head==null) { return head; } ListNode result=null; ListNode current=head; ListNode bigList=null; ListNode resultTal=null; ListNode bigTal=null; if(head.val>=x) { bigList=head; while(current.next!=null&¤t.next.val>=x) { current=current.next; } resultTal=result=current.next; bigTal=current; } else { result=head; while(current.next!=null&¤t.next.val<x) { current=current.next; } bigTal=bigList=current.next; resultTal=current; } if(current.next!=null)//current.next 已经处理 { current=current.next.next; } else { current=null; } while(current!=null) { if(current.val<x) { resultTal.next=current; resultTal=current; } else { bigTal.next=current; bigTal=current; } current=current.next; } if(bigTal!=null) { bigTal.next=null; } if(result==null) { return bigList; } resultTal.next=bigList; return result; }}
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
- laravel 配置 No supported encrypter found
- 5步搞定android混淆,一般项目还是别用吧,维护太痛苦。
- leetcode Longest Increasing Subsequence
- Android利用canvas画各种图形(点、直线、弧、圆、椭圆、文字、矩形、多边形、曲线、圆角矩形)
- 【BZOJ1633】[Usaco2007 Feb]The Cow Lexicon 牛的词典【DP】
- leetcode Partition List
- Windows运行GitStats
- VC 窗口焦点问题以及回车键,tab键的相关
- select简单2级联动
- sql 脚本的 指定数据库所有表的查询及指定表的所有列名的查询 / sql修改表名及修改列名称
- maven 的基本配置及个人理解
- Select2日常点滴
- 北航“CNI”预科
- 稳定方法 stabilization