Sinlge Linked List

reverse first k elements of a list. (Insert in Head 头插法)

int ct = k;
while (ct-- > 0) {
    ListNode *tmp = head->next;
    head->next = cur;
    cur = head;
    head = tmp;    
}

results matching ""

    No results matching ""