Rotate List Time : Space : 1234567891011121314151617181920212223242526/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ListNode* Solution::rotateRight(ListNode* A, int B) { ListNode* runner = A; for(int i = 0; i < B; i++) { runner = runner->next; if(!runner) runner = A; } if(runner == A) return A; ListNode* head = A; while(runner->next) { runner = runner->next; head = head->next; } runner->next = A; ListNode* res = head->next; head->next = NULL; return res;}