python solution, sorting and 2 pointers: O(max(glogg, slogs))


  • 0
    I
        def findContentChildren(self, g, s):
            """
            :type g: List[int]
            :type s: List[int]
            :rtype: int
            """
            g.sort()
            s.sort()
            g_len = len(g)
            s_len = len(s)
            
            j = 0
            i = 0
            content_children = 0
            
            while i < g_len and j < s_len:
                if s[j] >= g[i]: #can assign s[j] to g[i]
                    content_children += 1
                    j += 1
                    i += 1
                else: #need bigger cookie
                    j += 1
                    
            return content_children

Log in to reply
 

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