[HackerRank] Zig Zag Sequence - Problem
Q) 정수 배열 → Zig Zag Sequence 찾기
풀이
def findZigZagSequence(a, n):
a.sort()
mid = int(n/2) #modified
a[mid], a[n-1] = a[n-1], a[mid]
st = mid + 1
ed = n - 2 #modified
while(st <= ed):
a[st], a[ed] = a[ed], a[st]
st = st + 1
ed = ed - 1 #modified
for i in range (n):
if i == n-1:
print(a[i])
else:
print(a[i], end = ' ')
return
실행 결과