Skip to content

Commit 34db204

Browse files
Merge pull request #314 from morningsky/master
添加 0455.分发饼干 0376.摆动序列 python3版本
2 parents ff2ec86 + 82fc1ca commit 34db204

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

problems/0376.摆动序列.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,21 @@ class Solution {
138138
```
139139

140140
Python:
141-
141+
```python
142+
class Solution:
143+
def wiggleMaxLength(self, nums: List[int]) -> int:
144+
#贪心 求波峰数量 + 波谷数量
145+
if len(nums)<=1:
146+
return len(nums)
147+
cur, pre = 0,0 #当前一对差值,前一对差值
148+
count = 1#默认最右边有一个峰值
149+
for i in range(len(nums)-1):
150+
cur = nums[i+1] - nums[i]
151+
if((cur>0 and pre<=0) or (cur<0 and pre>=0)):
152+
count += 1
153+
pre = cur
154+
return count
155+
```
142156

143157
Go:
144158

problems/0455.分发饼干.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,21 @@ class Solution {
134134
```
135135

136136
Python:
137-
137+
```python
138+
class Solution:
139+
def findContentChildren(self, g: List[int], s: List[int]) -> int:
140+
#先考虑胃口小的孩子
141+
g.sort()
142+
s.sort()
143+
i=j=0
144+
count = 0
145+
while(i<len(g) and j<len(s)):
146+
if g[i]<=s[j]:
147+
count+=1
148+
i+=1 #如果满足了,则继续遍历下一个孩子和下一块饼干
149+
j += 1 #如果最小的饼干没有满足当前最小胃口的孩子,则遍历下一块饼干
150+
return count
151+
```
138152

139153
Go:
140154

0 commit comments

Comments
 (0)