일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 영어원서읽기
- 매일
- Daily Challenge
- realclass
- English
- leetcode
- 영어공부
- 월간
- 리얼 클래스
- 스탭퍼
- Problem Solving
- 괜찮음
- 잡생각
- 사이드
- 개발자
- 화상영어
- 읽기
- 쓰릴오브파이트
- 만화도
- 30분
- 미드시청
- 프로젝트
- FIT XR
- 3줄정리
- 뭐든
- 링피트
- 파비최
- Writing
- 10분
- 운동
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/daily-temperatures/
Daily Temperatures - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
단순히 풀면 O(n^2)으로 추정되는데,
그러면 10^10이라서 TL이 날 가능성이 매우 높음.
다른 사람이 푼 걸 보니, 뒤에서 부터 세어서 오면 매우 간단하게 풀림 =_=;;
class Solution:
def dailyTemperatures(self, temperatures: List[int]) -> List[int]:
l = len(temperatures)
ar = [-1] * 71
res = [0] * l
for i in range(l-1, -1, -1):
t = temperatures[i]
j = [x for x in ar[t-30+1:] if x > -1]
res[i] = 0 if len(j) == 0 else min(j)-i
ar[t-30] = i
return res
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.12.20 |
---|---|
Today's Challenge (0) | 2022.12.19 |
Today's Challenge (0) | 2022.12.17 |
Today's Challenge (0) | 2022.12.16 |
Today's Challenge (0) | 2022.12.15 |
Comments