Easy to understand python code


#1

class Solution:
def rotateArray(self, a, b):

    if b > len(a):
        b = b % len(a)
        
    if b == 0:
        return a
    
    ret = []
    temp1 = []
    temp2 = []
    i = 0
    
    while i<=(b-1):
        temp1.append(a[i])
        i += 1
    
    while i<len(a):
        temp2.append(a[i])
        i += 1
        
    
    ret = temp2 + temp1
    
    return ret

#2

As this ask just to fix the BUG in code, I just changed couple of lines and wrote the code in python. Hope this would help:

def rotateArray(self, a, b):
b %= len(a)
ret = []
for i in range(len(a)):
if i + b < len(a):
ret.append(a[i + b])
else:
ret.append(a[i + b - len(a)])
return ret