일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- tree
- GenerativeAI
- heap
- 코드업
- Python
- 파이썬기초100제
- stratascratch
- Python3
- Stack
- 투포인터
- 알고리즘
- SQL
- nlp
- 파이썬
- slidingwindow
- GenAI
- 생성형AI
- sql코테
- gcp
- medium
- dfs
- codeup
- 릿코드
- 자연어처리
- LeetCode
- 파이썬알고리즘
- 리트코드
- 슬라이딩윈도우
- 니트코드
- two-pointer
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] 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 |
[Leetcode/Stack,Tree] 897. Increasing Order Search Tree (0) | 2025.04.16 |