You are viewing a single comment's thread. Return to all comments →
Too short way for Array Rotation
Left Rotation:
def array_left_rotate(n, d): return n[d - 0:len(n) ] + (n[0:d - len(n)]) array_left_rotate([1,2,3,4,5],2)
Right Rotation:
def array_right_rotate(n, d): return (n[len(n) - d:len(n)]) + n[0:len(n) -d ] array_right_rotate([1,2,3,4,5,6],2)
Seems like cookies are disabled on this browser, please enable them to open this website
Arrays: Left Rotation
You are viewing a single comment's thread. Return to all comments →
Too short way for Array Rotation
Left Rotation:
def array_left_rotate(n, d): return n[d - 0:len(n) ] + (n[0:d - len(n)]) array_left_rotate([1,2,3,4,5],2)
Right Rotation:
def array_right_rotate(n, d): return (n[len(n) - d:len(n)]) + n[0:len(n) -d ] array_right_rotate([1,2,3,4,5,6],2)