NC23:划分链表
划分链表
http://www.nowcoder.com/practice/1dc1036be38f45f19000e48abe00b12f
解法1:模拟
public ListNode partition (ListNode head, int x) { // write code here ListNode small=new ListNode(0); ListNode smallHead=small; ListNode large=new ListNode(0); ListNode largeHead=large; while(head!=null){ if(head.val<x){ small.next=head; small=small.next; } else{ large.next=head; large=large.next; } head=head.next; } large.next=null; small.next=largeHead.next; return smallHead.next; }
名企高频面试算法题解 文章被收录于专栏
牛客题霸 - 程序员面试高频题 - 题解