455. 分发饼干
为保证权益,题目请参考 455. 分发饼干(From LeetCode).
解决方案1
Python
python
# 455
## 问题描述
## 解题
```python
from typing import List
import unittest
class Solution:
def findContentChildren(self, g: List[int], s: List[int]) -> int:
g.sort()
s.sort()
count = 0
for i in range(len(s)):
if count < len(g) and s[i] >= g[count]:
count += 1
return count
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
测试
python
class TestSolution(unittest.TestCase):
def setUp(self) -> None:
self.so = Solution()
return super().setUp()
def test_1(self):
self.assertEqual(self.so.findContentChildren(
[10, 9, 8, 7], [5, 6, 7, 8]), 2)
self.assertEqual(self.so.findContentChildren(
[10, 9, 8, 7], []), 0)
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
1