优化 0455. 分发饼干 python3版本

优化 0455. 分发饼干 python3版本
This commit is contained in:
jojoo15
2021-06-07 20:55:40 +02:00
committed by GitHub
parent a4b7399acb
commit 3fd92a4905

View File

@ -134,22 +134,17 @@ class Solution {
```
Python
```python
```python3
class Solution:
def findContentChildren(self, g: List[int], s: List[int]) -> int:
#先考虑胃口小的孩子
g.sort()
s.sort()
i=j=0
count = 0
while(i<len(g) and j<len(s)):
if g[i]<=s[j]:
count+=1
i+=1 #如果满足了,则继续遍历下一个孩子和下一块饼干
j += 1 #如果最小的饼干没有满足当前最小胃口的孩子,则遍历下一块饼干
return count
res = 0
for i in range(len(s)):
if res <len(g) and s[i] >= g[res]: #小饼干先喂饱小胃口
res += 1
return res
```
Go
Javascript: