while ( first != last ) { auto tmp = first->next; first->next = prev; prev = first; first = tmp; }
return prev; }
ListNode* reverseKGroup(ListNode* head, int k) { auto node=head; for (int i=0; i < k; ++i) { if ( ! node ) return head; // nothing to do list too sort node = node->next; }
funcbinsearch(stack []int, x int)(r int) { l, r := 0, len(stack) for l < r { m := l + (r - l) / 2 if stack[m] >= x { r = m } else { l = m + 1 } } return }
for _, num := range nums { r := binsearch(stack, num) if r < 0 { stack[0] = num } elseif r == len(stack) { stack = append(stack, num) } else { stack[r] = num } }