Skip to content

Commit ed081cd

Browse files
committed
programmers.co.kr 코딩테스트 연습_월간 코드 챌린지 시즌1_풍선 터트리기
문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/68646
1 parent 846e453 commit ed081cd

File tree

2 files changed

+32
-0
lines changed
  • programmers.co.kr 코딩테스트 연습_월간 코드 챌린지 시즌1_풍선 터트리기

2 files changed

+32
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
from typing import List
3+
4+
5+
def solution(nums: List[int]):
6+
nums = [sys.maxsize] + nums + [sys.maxsize]
7+
l = len(nums)
8+
answer = 0
9+
mins_l2r = [sys.maxsize] * l
10+
mins_r2l = [sys.maxsize] * l
11+
12+
for idx in range(1, l):
13+
mins_l2r[idx] = min(mins_l2r[idx - 1], nums[idx])
14+
15+
for idx in range(l - 1 - 1, -1, -1):
16+
mins_r2l[idx] = min(mins_r2l[idx + 1], nums[idx])
17+
18+
for idx in range(1, l - 1):
19+
if not (mins_l2r[idx - 1] < nums[idx] and mins_r2l[idx + 1] < nums[idx]):
20+
answer += 1
21+
22+
return answer
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from unittest import TestCase
2+
from main import solution
3+
4+
5+
class Test(TestCase):
6+
def test1_solution(self):
7+
self.assertEqual(3, solution([9, -1, -5]))
8+
9+
def test2_solution(self):
10+
self.assertEqual(6, solution([-16, 27, 65, -2, 58, -92, -71, -68, -61, -33]))

0 commit comments

Comments
 (0)