Skip to content

Commit 40c29aa

Browse files
authored
Update 455.AssignCookies.md
1 parent 6173063 commit 40c29aa

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

problems/455.AssignCookies.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ https://leetcode-cn.com/problems/assign-cookies/
6161

6262
## 代码
6363

64-
语言支持:JS
64+
语言支持:JS, Python
6565

66+
JS Code:
6667
```js
6768
/**
6869
* @param {number[]} g
@@ -90,6 +91,22 @@ const findContentChildren = function (g, s) {
9091
};
9192
```
9293

94+
Python Code:
95+
```python
96+
from typing import *
97+
class Solution:
98+
def findContentChildren(self, g: List[int], s: List[int]) -> int:
99+
g.sort(reverse=True)
100+
s.sort(reverse=True)
101+
count=gIdx=sIdx=0
102+
while gIdx<len(g) and sIdx<len(s):
103+
if s[sIdx]>=g[gIdx]:
104+
sIdx+=1
105+
count+=1
106+
gIdx+=1
107+
return count
108+
```
109+
93110
***复杂度分析***
94111

95112
- 时间复杂度:由于使用了排序,因此时间复杂度为 O(NlogN)

0 commit comments

Comments
 (0)