455. Assign Cookies
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 54% Topics: Array, Two Pointers, Greedy, Sorting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(nlogn)
# Space: O(1)
class Solution(object):
def findContentChildren(self, g, s):
"""
:type g: List[int]
:type s: List[int]
:rtype: int
"""
g.sort()
s.sort()
result, i = 0, 0
for j in xrange(len(s)):
if i == len(g):
break
if s[j] >= g[i]:
result += 1
i += 1
return result
Solution from kamyu104/LeetCode-Solutions · MIT