File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -138,7 +138,21 @@ class Solution {
138
138
```
139
139
140
140
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
+ ```
142
156
143
157
Go:
144
158
Original file line number Diff line number Diff line change @@ -134,7 +134,21 @@ class Solution {
134
134
```
135
135
136
136
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
+ ```
138
152
139
153
Go:
140
154
You can’t perform that action at this time.
0 commit comments