https://www.acmicpc.net/problem/2491
풀이
문제를 보았을때 알수있는 힌트
나열된 수열이 있는데 이때 연속해서 커지거나 작아지는 경우 연속된 길이를 출력하는 문제
처음부터 마지막까지 2개씩을 확인하여 커지는지, 작아지는지 확인한다. 커져야하는데 작아지는경우 다시 개수를 세며 진행한다.
import sys
input = sys.stdin.readline
n = int(input())
n_list=tuple(map(int,input().split()))
start=1
max_len=1
temp=[1,1]
while start<=n-1:
if n_list[start-1]<=n_list[start]:
temp[0]+=1
else:
temp[0]=1
if n_list[start-1]>=n_list[start]:
temp[1]+=1
else:
temp[1]=1
max_len=max(max_len,temp[0],temp[1])
start+=1
print(max_len)
https://github.com/dydwkd486/coding_test/blob/main/baekjoon/baekjoon2491.py
GitHub - dydwkd486/coding_test: 코딩테스트 공부한 내용 정리
코딩테스트 공부한 내용 정리. Contribute to dydwkd486/coding_test development by creating an account on GitHub.
github.com
'Coding Test > baekjoon' 카테고리의 다른 글
[백준 11725] 점프 점프 - python (solved.ac - 실버 2) (0) | 2022.01.12 |
---|---|
[백준 11725] 트리의 부모 찾기 - python (solved.ac - 실버 2) (0) | 2022.01.11 |
[백준 14889] 스타트와 링크 - python (solved.ac - 실버 3) (0) | 2022.01.09 |
[백준 2805] 나무 자르기 - python (solved.ac - 실버 3) (0) | 2022.01.08 |
[백준 1654] 랜선 자르기 - python (solved.ac - 실버 3) (0) | 2022.01.07 |