Skip to content

Commit

Permalink
Create Arrayrotate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeHiestIndia authored Oct 31, 2020
1 parent 354e735 commit 8e942ab
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Python/Arrayrotate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#code by codeheist India
def leftRotate(arr, d, n):
for i in range(gcd(d,n)):
temp = arr[i]
j = i
while 1:
k = j + d
if k >= n:
k = k - n
if k == i:
break
arr[j] = arr[k]
j = k
arr[j] = temp
def printArray(arr, size):
for i in range(size):
print ("%d" % arr[i], end=" ")

def gcd(a, b):
if b == 0:
return a;
else:
return gcd(b, a%b)

arr = [1, 2, 3, 4, 5, 6, 7]
leftRotate(arr, 2, 7)
printArray(arr, 7)

0 comments on commit 8e942ab

Please sign in to comment.