[Programmers] ์ฃผ์‹ ๊ฐ€๊ฒฉ

Updated:

์ฃผ์‹ ๊ฐ€๊ฒฉ

์ฃผ์‹ ๊ฐ€๊ฒฉ ์„ ํด๋ฆญํ•˜๋ฉด ๋ฐ”๋กœ ์ด๋™ํ•œ๋‹ค.

ํšจ์œจ์„ฑ๋„ ๋”ฐ์กŒ๋˜ ๋ฌธ์ œ์˜€์ง€๋งŒ deque ๋ฅผ ์‚ฌ์šฉํ•ด ํ†ต๊ณผํ–ˆ๋‹ค !

from collections import deque


def solution(prices):
	answer = list()
	prices = deque(prices)

	while prices:
		check = prices.popleft()
		sec = 0

		for val in prices:
			sec += 1
			if check <= val:
				continue
			else:
				break
		answer.append(sec)

	return answer

์ฃผ์‹ ๊ฐ€๊ฒฉ์ด ๋ช‡ ์ดˆ ๋™์•ˆ ๋–จ์–ด์ง€์ง€ ์•Š์•˜๋‚˜๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๋ฌธ์ œ๋‹ค.

๋ฐ˜๋ณต๋ฌธ์— ๋“ค์–ด์™€์„œ ๋ฌด์กฐ๊ฑด ์ดˆ๋Š” 1์ดˆ๋ฅผ ๋”ํ•ด ์ค€ ๋’ค ๊ฐ’์„ ๋น„๊ตํ•ด์„œ ๋”ฐ์ง€๋ฉด

๊ธˆ๋ฐฉ ํ’€ ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ.

prices ๋ฅผ list ๊ทธ๋Œ€๋กœ ํ’€๊ฒŒ ๋˜๋ฉด ํšจ์œจ์„ฑ์—์„œ ์ „๋ถ€ ์‹œ๊ฐ„์ดˆ๊ณผ๊ฐ€ ๋‚˜์™€ ํ‹€๋ฆฌ๊ฒŒ ๋œ๋‹ค.

์™ผ์ชฝ ๋ถ€ํ„ฐ ๋ฝ‘์•„์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ ๊ผญ deque ๋ฅผ ์‚ฌ์šฉํ•˜์ž !!

[Python] List VS Queue


Categories:

Updated:

Leave a comment