When I trying to solve LeetCode's task "Rotate Array" I have an error "Time Limit Exceeded", because on one of the task's test cases checkings I have following input: list named "sums" with 100k items and "k" variable = 54944.
The task description: "Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.".
My solution's code on python v. 2:
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.
"""
c = 0
c_max = k - 1
nums.reverse()
while c <= c_max:
nums.append(nums[0])
del nums[0]
c = c + 1
nums.reverse()
How I should optimize this code to resolve the error?