- 86
- class Solution {
- public ListNode partition(ListNode head, int x) {
- ListNode lowheader=new ListNode(0);
- ListNode low=lowheader;
- ListNode highheader=new ListNode(0);
- ListNode high=highheader;
- while(head!=null){
- if(head.val<x){
- low.next=head;
- head=head.next;
- low=low.next;
- low.next=null;
- }else{
- high.next=head;
- head=head.next;
- high=high.next;
- high.next=null;
- }
- }
- low.next=highheader.next;
- return lowheader.next;
- }
- }
来源: http://www.bubuko.com/infodetail-2967770.html