문제
https://leetcode.com/problems/assign-cookies/
Assign Cookies - 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
생각
으음 그러면 애들이 원하는 사이즈와 쿠키의 크기가 정렬되어있는건가? 그렇진 않겠지?
애들이 원하는 사이즈보다 쿠키가 같거나 크면 output 수를 1 더해주기.
이미 만족한 쿠키면 다음 쿠키부터.
쿠키를 기준으로 진행해야됨! 쿠키를 분배해주는 것이니까.
코드
class Solution:
def findContentChildren(self, g: List[int], s: List[int]) -> int:
g.sort()
s.sort()
content = 0
nextCookie = 0
for j in range(0, len(s)):
for i in range(nextCookie, len(g)):
if s[j] >= g[i]:
content += 1
nextCookie = i+1
break
return content
너무 오랜만에 파이썬을 해서 너무 헷갈렸다...
'문제 > 릿코드' 카테고리의 다른 글
[릿코드/LeetCode] 206. Reverse Linked List (파이썬3/Python3) (0) | 2021.07.18 |
---|---|
[릿코드/LeetCode] 342. Power of Four (파이썬3/Python3) (4) | 2021.07.11 |
[릿코드/LeetCode] 551. Student Attendance Record I (파이썬3/Python3) (0) | 2021.07.11 |
[릿코드/LeetCode] 14. Longest Common Prefix (파이썬3/Python3) (0) | 2021.07.10 |
[릿코드/LeetCode] 66. Plus One (파이썬3/Python3) (0) | 2021.07.08 |