일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Daily Challenge
- 리얼 클래스
- 링피트
- 잡생각
- 괜찮음
- 프로젝트
- 개발자
- 30분
- 영어공부
- 읽기
- Writing
- leetcode
- 만화도
- 스탭퍼
- English
- 파비최
- 화상영어
- 사이드
- 3줄정리
- 10분
- 월간
- 뭐든
- FIT XR
- 미드시청
- Problem Solving
- 매일
- 쓰릴오브파이트
- 운동
- realclass
- 영어원서읽기
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.04.02 Today's Challenge 본문
https://leetcode.com/problems/successful-pairs-of-spells-and-potions/
Successful Pairs of Spells and Potions - LeetCode
Can you solve this real interview question? Successful Pairs of Spells and Potions - You are given two positive integer arrays spells and potions, of length n and m respectively, where spells[i] represents the strength of the ith spell and potions[j] repre
leetcode.com
무식하게 풀면 바로 TL 나옴.
정렬도 했는 TL.
정렬 + 이분 탐색 해야 통과됨.
class Solution:
def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:
res = []
l = len(potions)
potions.sort()
max_potion = potions[l-1]
for spell in spells:
min_potion = (success + spell - 1) // spell
if min_potion > max_potion:
res.append(0)
continue
idx = bisect.bisect_left(potions, min_potion)
res.append(l - idx)
return res
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.04.04 Today's Challenge (0) | 2023.04.04 |
---|---|
2023.04.03 Today's Challenge (0) | 2023.04.03 |
2023.04.01 Today's Challenge (0) | 2023.04.01 |
2023.03.31 Today's Challenge (0) | 2023.03.31 |
2023.03.30 Today's Challenge (0) | 2023.03.30 |
Comments