class Solution:
def findContentChildren(self, g, s):
"""
:type g: List[int]
:type s: List[int]
:rtype: int
"""
g.sort()
s.sort()
len1=len(g)
len2=len(s)
i=0
j=0
num=0
while i<len1 and j<len2:
if g[i]<=s[j]:
num+=1
i+=1
j+=1
return num
这段代码就显示通过。而下面这段讲j+=1
加入到if
中就会变成超时,这是为什么?
class Solution:
def findContentChildren(self, g, s):
"""
:type g: List[int]
:type s: List[int]
:rtype: int
"""
g.sort()
s.sort()
len1=len(g)
len2=len(s)
i=0
j=0
num=0
while i<len1 and j<len2:
if g[i]<=s[j]:
num+=1
i+=1
j+=1
return num