[배열] 백준 2864 오르막길

정은경·2020년 5월 17일
0

백준 문제풀이

목록 보기
8/51

1. 문제


2. 나의 풀이

count = int(input())
nums = [int(x) for x in input().split()]
prev = nums[0]
rlt = list()
temp = list()
temp.append(prev)

is_up = True

if count == 1:
    print(0)
else:
    for i in range(1, count):
        if prev < nums[i]:
            pass
        else:
            rlt.append(temp)
            temp = list()
            # print(prev, rlt)
        prev = nums[i]
        temp.append(prev)

rlt.append(temp)

max_height = 0
for i in rlt:
    temp = (max(i)-min(i))
    if max_height < temp:
        max_height = temp
print(max_height)

3. 남의 풀이

N = int(input())
arr = list(map(int, input().split()))
pre = arr[0]
max_h = 0
tmp = [arr[0]]

for h in arr[1:]:
    if h > pre:
        tmp.append(h)
        pre = h
    elif h <=pre:
        h_d = tmp[-1] - tmp[0]
        if h_d > max_h:
            max_h = h_d
        tmp = [h]
    pre = h
if len(tmp) >= 2:
    h_d = tmp[-1] - tmp[0]
    if h_d > max_h:
        max_h = h_d
print(max_h)

4. 느낀 점

  • 오랜만에 푸는 알고리즘 문제
  • 쉬운 문제인데 금방 안풀렸던 걸까?
profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글