ps | |
---|---|
링크 | programmers.co.kr/… |
출처 | 프로그래머스 |
문제 번호 | 68646 |
문제명 | 풍선 터트리기 |
레벨 | Level 3 |
분류 |
애드혹 |
시간복잡도 | O(n) |
인풋사이즈 | n<=1,000,000 |
사용한 언어 | Python |
해결날짜 | 2020/12/07 |
def solution(a):
min_lnum = min_rnum = float('inf')
return (len([(min_lnum := num) for num in a if num < min_lnum])
+ len([(min_rnum := num) for num in reversed(a) if num < min_rnum])
- 1)
"""Solution code for "Programmers 68646. 풍선 터트리기".
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/68646
- Solution link: http://www.teferi.net/ps/problems/programmers/68646
"""
INF = float('inf')
def solution(a):
answer = 0
min_num = INF
for num in a:
if num < min_num:
answer += 1
min_num = num
min_num = INF
for num in reversed(a):
if num < min_num:
answer += 1
min_num = num
return answer - 1
"""Solution code for "Programmers 68646. 풍선 터트리기".
Compact code using walrus operater in list comprehension.
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/68646
- Solution link: http://www.teferi.net/ps/problems/programmers/68646
"""
INF = float('inf')
def solution(a):
answer = 0
min_num = INF
answer += len([(min_num := num) for num in a if num < min_num])
min_num = INF
answer += len([(min_num := num) for num in reversed(a) if num < min_num])
return answer - 1