일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 니트코드
- 알고리즘
- dfs
- 파이썬
- 릿코드
- 자연어처리
- sql코테
- 파이썬기초100제
- stratascratch
- 슬라이딩윈도우
- SQL
- array
- GenerativeAI
- 리트코드
- Greedy
- nlp
- Python
- Stack
- two-pointer
- slidingwindow
- heap
- Python3
- 생성형AI
- gcp
- 파이썬알고리즘
- 코드업
- 투포인터
- LeetCode
- GenAI
- codeup
Archives
- Today
- Total
Tech for good
[Leetcode/Sort, Greedy, Two-pointer] 455. Assign Cookies 본문
IT/Computer Science
[Leetcode/Sort, Greedy, Two-pointer] 455. Assign Cookies
Diana Kang 2025. 5. 3. 03:32Look through Example
- g = child A want 1 number of cookie, child B want 2 number of cookies, child C want 3 number of cookies
- s = cookie A is 1 number of cookie, cookie B is 2 number of cookies
class Solution:
def findContentChildren(self, g: List[int], s: List[int]) -> int:
g.sort()
s.sort()
child = 0 # pointer to children
cookie = 0 # pointer to cookies
while child < len(g) and cookie < len(s):
if s[cookie] >= g[child]:
child += 1 # child is content, move to next child
cookie += 1 # move to next cookie
return child # number of content children
'IT > Computer Science' 카테고리의 다른 글
[Leetcode/Array, Greedy] 976. Largest Perimeter Triangle (0) | 2025.05.23 |
---|---|
[Leetcode/Array, Greedy] 860. Lemonade Change (0) | 2025.05.05 |
[Leetcode/Sort, Greedy] 561. Array Partition (0) | 2025.05.02 |
[Leetcode/Stack,Queue] 1700. Number of Students Unable to Eat Lunch (0) | 2025.04.22 |
[Leetcode/Stack] 1614. Maximum Nesting Depth of the Parentheses (0) | 2025.04.21 |