문제/릿코드

[릿코드/LeetCode] 455. Assign Cookies (파이썬3/Python3)

개 살구 2021. 7. 7. 23:14

문제

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

 

너무 오랜만에 파이썬을 해서 너무 헷갈렸다...