인프런 커뮤니티 질문&답변
합병정렬처럼 풀었는데 이 코드는 어떤가요?
해결된 질문
작성
·
180
0
import sys
#sys.stdin=open('input.txt', 'rt')
n = int(input())
a = list(map(int, input().split()))
cnt = 0
left = 'L'
right = 'R'
lf = 0
rt = len(a)-1
cur = 0
str = ""
while(cur<a[lf] and cur<a[rt]):
if(a[lf]>=a[rt]):
cur = a[rt]
cnt+=1
str += right
rt-=1
else:
cur = a[lf]
cnt+=1
str += left
lf+=1
while(cur<a[lf]):
cur = a[lf]
lf+=1
str+=left
cnt+=1
while(cur<a[rt]):
cur = a[rt]
rt-=1
str+=right
cnt+=1
print(cnt)
print(str)





