贪心_leetcode455

class Solution(object):
def findContentChildren(self, g, s):
"""
:type g: List[int]
:type s: List[int]
:rtype: int
"""


g.sort(reverse = True)
s.sort(reverse = True)

res = 0

gIndex = 0
sIndex = 0

while gIndex < len(g) and sIndex < len(s):
if s[sIndex] >= g[gIndex]:
res += 1
gIndex += 1
sIndex += 1
else:
gIndex += 1


return res




s = Solution()

g1 = [1,2,3]

s1 = [1,1]


print s.findContentChildren(g1,s1)
posted @ 2019-03-19 10:19  AceKo  阅读(119)  评论(0编辑  收藏  举报