# ๐ก Daily Temperatures

ํ๋ฆฌ๋ยท2021๋ 8์ 26์ผ
0

๋ฆฌํธ์ฝ๋ 739๋ฒ ์ผ์ผ์จ๋ ๋ดํ์ด์ ์๊ธธ์ ์๋ ํ์ด ๋น๊ต

• ๋ฌธ์  ์๊ตฌ์ฌํญ์ ์ฌ์ดํธ์ ๋ค์ด๊ฐ์ ํ์ธํ์.

# ๋ดํ์ด

from collections import deque
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
temperatures = deque(temperatures)
for i in range(len(temperatures)):
a = temperatures.popleft()
while True:
j = 0
if temperatures[j] <= a:
j += 1
elif temperatures[j] > a:
j += 1
break
if j >= len(temperatures):
break

• ๊ฐ์ฅ ์ฒ์ ๊ณ ๋ฏผํ ๊ฑด for๋ฌธ์ ํ๋ฒ๋ง ์ฐ๊ณ  ๊ตฌํํ๋ ๋ฒ์ ๋ํด์ ๊ณ ๋ฏผํ๋ค.
์ฒ์์๋ while๋ฌธ๋ง ์ฌ์ฉํด์ ํ๋ ค๊ณ  ํ์ผ๋ ํ๋์ฉ ๋ค ๋น๊ต๋ฅผ ํด์ผ ํ๋ฏ๋ก for๋ฌธ์ while๋ฌธ์ ๋ฃ๋ ๊ฑธ๋ก ํํ์ ๋ดค๋ค.

• ์ฒซ๋ฒ์งธ ๋ฐ๋ณต๋ฌธ์์ ์์ ์์๋ฅผ ๋นผ๊ณ  ๋ค์ while ๋ฐ๋ณต๋ฌธ์ ์ํํ๋ฉด์ ์ธ๋ฑ์ค๋ฅผ ์ ์ฅํ๋ ๋ณ์ j๋ฅผ ์ ์ธํด์ ๊ฐ ์กฐ๊ฑด๋ง๋ค j๊ฐ์ 1์ฉ ์ฌ๋ฆฌ๋ค๊ฐ ์กฐ๊ฑด์ ํด๋นํ๋ฉด ๋น ๋ฐฐ์ด์ j๋ฅผ ์ง์ด ๋ฃ๋๋ค.

• ๊ทธ์น๋ง ์๊ฐ์ด๊ณผ๊ฐ ๋์ ์ฒด์ ์กฐ์ฐจ ๋์ง ์์๋ค....

# ์๊ธธ ์ ์๋์ ํ์ด

class Solution:
def dailyTemperatures(self, T: List[int]) -> List[int]:
stack = []
for i, cur in enumerate(T):
# ํ์ฌ ์จ๋๊ฐ ์คํ ๊ฐ๋ณด๋ค ๋๋ค๋ฉด ์ ๋ต ์ฒ๋ฆฌ
while stack and cur > T[stack[-1]]:
last = stack.pop()
return answer