"""Leetcode 189. Rotate Array
Easy

URL: https://leetcode.com/problems/rotate-array/

Given an array, rotate the array to the right by k steps, where k is non-negative.

Example 1:
Input: [1,2,3,4,5,6,7] and k = 3
Output: [5,6,7,1,2,3,4]
Explanation:
rotate 1 steps to the right: [7,1,2,3,4,5,6]
rotate 2 steps to the right: [6,7,1,2,3,4,5]
rotate 3 steps to the right: [5,6,7,1,2,3,4]

Example 2:
Input: [-1,-100,3,99] and k = 2
Output: [3,99,-1,-100]
Explanation: 
rotate 1 steps to the right: [99,-1,-100,3]
rotate 2 steps to the right: [3,99,-1,-100]

Note:
- Try to come up as many solutions as you can, 
  there are at least 3 different ways to solve this problem.
- Could you do it in-place with O(1) extra space?
"""

class SolutionCopy(object):
    def rotate(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: None Do not return anything, modify nums in-place instead.

        Time complexity: O(n).
        Space complexity: O(n).
        """
        # If k >= n, truncate k by n.
        n = len(nums)
        if k >= n:
            k -= n

        # Append right with left.
        nums[:] = nums[-k:] + nums[:-k]


def main():
    # Ans: [5,6,7,1,2,3,4]
    nums = [1,2,3,4,5,6,7]
    k = 3
    SolutionCopy().rotate(nums, k)
    print nums

    # Ans: [3,99,-1,-100]
    nums = [-1,-100,3,99]
    k = 2
    SolutionCopy().rotate(nums, k)
    print nums

    # Ans: [2,1]
    nums = [1,2]
    k = 3
    SolutionCopy().rotate(nums, k)
    print nums


if __name__ == '__main__':
    main()

@@ -1064,35 +1064,15 @@
     
-if 
 k 
-%3E
 = 
-n:%0A            k -=
+k %25
  n%0A%0A
@@ -1147,16 +1147,800 @@
 %5B:-k%5D%0A%0A%0A
+class SolutionIter(object):%0A    def rotate(self, nums, k):%0A        %22%22%22%0A        :type nums: List%5Bint%5D%0A        :type k: int%0A        :rtype: None Do not return anything, modify nums in-place instead.%0A%0A        Time complexity: O(n).%0A        Space complexity: O(n).%0A        %22%22%22%0A        # If k %3E= n, truncate k by n.%0A        n = len(nums)%0A        k = k %25 n%0A%0A        count = 0%0A        start_pos, cur_pos = 0, 0%0A%0A        while count %3C n:%0A            next_pos = (cur_pos + k) %25 n%0A            temp_num = nums%5Bnext_pos%5D%0A            # TODO: 2019/08/30%0A            nums%5Bnew%5D = rotate_num%0A            rotate_num = temp_num%0A%0A            while current != start:%0A%0A%0A                count += 1%0A                print nums%0A%0A            start += 1%0A            current = s%0A%0A        nums%5Bnew_id%5D = old_num%0A%0A%0A
 def main
@@ -2002,32 +2002,49 @@
 7%5D%0A    k = 3%0A   
+ print nums%0A    #
  SolutionCopy().
@@ -2051,32 +2051,67 @@
 rotate(nums, k)%0A
+    SolutionIter().rotate(nums, k)%0A
     print nums%0A%0A
@@ -2171,24 +2171,41 @@
    k = 2%0A   
+ print nums%0A    #
  SolutionCop
@@ -2216,32 +2216,67 @@
 rotate(nums, k)%0A
+    SolutionIter().rotate(nums, k)%0A
     print nums%0A%0A
@@ -2323,28 +2323,80 @@
 = 3%0A    
-SolutionCopy
+print nums%0A    # SolutionCopy().rotate(nums, k)%0A    SolutionIter
 ().rotat

Implement iter sol