标签:reverse next des span log while solution nbsp div
class Solution { public ListNode reverseKGroup(ListNode head, int k) { if(head==null||k==1) return head; ListNode preNode=new ListNode(0); preNode.next=head; ListNode pre=preNode, cur=pre, nex; int num=0; while(cur.next!=null) { num++; cur=cur.next; } while(num>=k) { cur=pre.next; nex=cur.next; for(int i=1;i<k;i++) { cur.next=nex.next; nex.next=pre.next; pre.next=nex; nex=cur.next; } pre=cur; num-=k; } return preNode.next; } }
标签:reverse next des span log while solution nbsp div
原文地址:http://www.cnblogs.com/asuran/p/7580055.html