문제 링크

문제 설명

예시

[input]
6
1 2 3 2 2 1

[output]
2


[input]
9
1 2 1 2 1 2 1 2 1

[output]
5


[input]
7
1 2 3 2 1 999999999 1000000000

[output]
3

사고의 흐름

모범답안

1. 여기를 누르면 답이 보입니다
def answer(arr):
    n = len(arr)
    count = 0
    INC = 'INCREASING'
    DEC = 'DECREASING'
    STATE = None
    if n == 1 or n == 2:
        return 1
    for i in range(n-1):
        diff = arr[i+1] - arr[i]
        if diff == 0:
            continue
        if STATE is None:
            if diff > 0:
                STATE = INC
            if diff < 0:
                STATE = DEC
            count += 1
        elif STATE is INC:
            if diff < 0:
                STATE = None
        elif STATE is DEC:
            if diff > 0:
                STATE = None
        if STATE is None and i == n-2:
            count += 1
            
    return count

n = int(input())
arr = list(map(int, input().split()))
print(answer(arr))
2. 여기를 누르면 답이 보입니다