Search

๊น€๋ฏผ์ง€

2.๋ฌธ์ œ์ด๋ฆ„
3. ์ˆ˜ํ–‰์‹œ๊ฐ„[์ดˆ(s)]
300
์ข‹์•„์š” ๋ˆ„๋ฅด๊ธฐ
์ข‹์•„์š” ์ˆ˜
: 0
5 more properties
| ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ
import heapq def solution(scoville, K): heapq.heapify(scoville) answer=0 while scoville[0]<K : if len(scoville)==1 : return -1 a=heapq.heappop(scoville) b=heapq.heappop(scoville) heapq.heappush(scoville, a+b*2) answer+=1 return answer
Python
๋ณต์‚ฌ
| ์ฝ”๋“œ ์„ค๋ช…ํ•˜๊ธฐ
1.
scoville ๋ฆฌ์ŠคํŠธ๋ฅผ ํž™ํ๋กœ ๋ณ€๊ฒฝ
2.
์Šค์ฝ”๋นŒ์ง€์ˆ˜๊ฐ€ ์ œ์ผ ์ž‘์€ ๊ฐ’์ด K๋ณด๋‹ค ์ž‘์„ ๋•Œ ๋ฐ˜๋ณตํ•œ๋‹ค.
a.
scoville ๋ฆฌ์ŠคํŠธ์˜ ๊ธธ์ด๊ฐ€ 1์ด๋ฉด ๋” ์ด์ƒ ์ง„ํ–‰ํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ -1์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
b.
์ œ์ผ ์ž‘์€ ๊ฐ’๊ณผ ๋‘๋ฒˆ์งธ๋กœ ์ž‘์€ ๊ฐ’์„ ํž™ํ์—์„œ ์‚ญ์ œํ•˜๊ณ  ์ œ์ผ ์ž‘์€ ๊ฐ’+ ๋‘๋ฒˆ์งธ๋กœ ์ž‘์€ ๊ฐ’*2๋ฅผ ๊ณ„์‚ฐํ•œ ๊ฐ’์„ ํž™ํ์— ๋„ฃ๋Š”๋‹ค.
c.
answer๋ฅผ 1 ์ฆ๊ฐ€์‹œํ‚จ๋‹ค.