I’m doing Leetcode #189 which is array rotation. I decide to do this by splitting the array into two arrays and join them.
Following is my code:
class Solution(object): def rotate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: None Do not return anything, modify nums in-place instead. """ num1 =  num2 =  for i in range(0, len(nums)-k): num1.append(nums[i]) for j in range(len(nums)-k, len(nums)): num2.append(nums[j]) num2.extend(num1) print(num2)
but my output is wrong on Leetcode but right on Pycharm. Why? Is there anything wrong in the code?
Source: Python Questions