Simple PYTHON O(nlogn)


  • 8
    V
    class Solution(object):
        def findContentChildren(self, g, s):
            """
            :type g: List[int]
            :type s: List[int]
            :rtype: int
            """
            g.sort()
            s.sort()
            
            childi = 0
            cookiei = 0
            
            while cookiei < len(s) and childi < len(g):
                if s[cookiei] >= g[childi]:
                    childi += 1
                cookiei += 1
            
            return childi
                    
    

  • 0
    1

    Thanks! short&beautiful!


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.