# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: # @param head, a ListNode # @param k, an integer # @return a ListNode def rotateRight(self, head, k): if not head: return None test=head n=1 while test.next: test=test.next n+=1 test.next=head for i in range(n-k%n): test=test.next rst=test.next test.next=None return rst
Thursday, September 18, 2014
Leetcode: Rotate List @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment