mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
@ -134,22 +134,17 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
```python
|
```python3
|
||||||
class Solution:
|
class Solution:
|
||||||
def findContentChildren(self, g: List[int], s: List[int]) -> int:
|
def findContentChildren(self, g: List[int], s: List[int]) -> int:
|
||||||
#先考虑胃口小的孩子
|
|
||||||
g.sort()
|
g.sort()
|
||||||
s.sort()
|
s.sort()
|
||||||
i=j=0
|
res = 0
|
||||||
count = 0
|
for i in range(len(s)):
|
||||||
while(i<len(g) and j<len(s)):
|
if res <len(g) and s[i] >= g[res]: #小饼干先喂饱小胃口
|
||||||
if g[i]<=s[j]:
|
res += 1
|
||||||
count+=1
|
return res
|
||||||
i+=1 #如果满足了,则继续遍历下一个孩子和下一块饼干
|
|
||||||
j += 1 #如果最小的饼干没有满足当前最小胃口的孩子,则遍历下一块饼干
|
|
||||||
return count
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
Javascript:
|
Javascript:
|
||||||
|
Reference in New Issue
Block a user