일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- til
- C++
- Counting cells in a blob
- 피보나치 수
- codesignal
- Python
- centuryFromYear
- 2750
- collections.deque
- recursion
- data_structure
- 백준
- Daily Commit
- Sequential Search
- cpp
- adjacentElementsProduct
- matrixElementsSum
- Numpy
- 10953
- baekjun
- shapeArea
- almostIncreasingSequence
- 2015 봄학기 알고리즘
- codesingal
- All Longest Strings
- 파이썬 포렌식
- 파이썬머신러닝완벽가이드
- markdown
- 수 정렬하기
- flask
Archives
- Today
- Total
Introfor
[Intro] almostIncreasingSequence 본문
Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array.
Note: sequence a0, a1, ..., an is considered to be a strictly increasing if a0 < a1 < ... < an. Sequence containing only one element is also considered to be strictly increasing.
일련의 증가하는 시퀀스를 가지는가를 판별하는 문제다.
도저히 알고리즘이 생각나지 않아 타인의 코드를 가지고 왔다.
def almostIncreasingSequence(sequence):
droppped = False
last = prev = min(sequence)-1
for elm in sequence:
if elm <= last:
if droppped:
return False
else:
droppped = True
if elm <= prev:
prev = last
elif elm >= prev:
prev = last = elm
else:
prev, last = last, elm
return True
'Programming_prob > Codesignal' 카테고리의 다른 글
[Intro] All Longest Strings (0) | 2020.07.18 |
---|---|
[Intro] matrixElementsSum (0) | 2020.07.18 |
[Intro] Make Array Consecutive 2 (0) | 2020.07.18 |
[Intro] shapeArea (0) | 2020.07.18 |
[Intro] adjacentElementsProduct (0) | 2020.07.18 |
Comments