Rotate List

Descrição

FlashCards sobre Rotate List, criado por Suhas S em 27-02-2018.
Suhas S
FlashCards por Suhas S, atualizado more than 1 year ago
Suhas S
Criado por Suhas S quase 8 anos atrás
1
0

Resumo de Recurso

Questão Responda
Given 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; }

Semelhante

Linked List
Subash M
Delete Node in a BST
Suhas S
Delete a node with a key
Suhas S
Remove Nth Node From End of List
Suhas S
Swap Nodes in Pairs
Suhas S
Merge Two Sorted Lists
Suhas S
Odd Even Linked List
Suhas S
Add Two Numbers
Suhas S
Copy List with Random Pointer
Suhas S