GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

Rotate List

Suhas S Englisch 1 Karte

Karten in diesem Stapel (1)

  1. 1Given a list, rotate the list to the right by k places, where k is non-negative.public ListNode rotateRight(ListNode head, int k) {
    if(head==null || head.next==null) return head;
    ListNode dummy = new ListNode(0);
    dummy.next = head;
    ListNode fast = dummy;
    ListNode slow = dummy;
    int count = 0;
    while(fast.next != null){
    fast = fast.next;
    count++;
    }
    for(int i = count - k % count; i>0; i--){
    slow = slow.next;
    }
    fast.next = dummy.next;
    dummy.next = slow.next;
    slow.next = null;
    return dummy.next;
    }

Informationen

Beschreibung
Karteikarten am Rotate List, erstellt von Suhas S am 27/02/2018.
Erstellt von
Suhas S
Aufrufe
10
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck