From 41c4f17833df822a740ae2b901fb3bb530b5b47b Mon Sep 17 00:00:00 2001 From: evanlai Date: Wed, 2 Jun 2021 23:39:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200455.=E5=88=86?= =?UTF-8?q?=E5=8F=91=E9=A5=BC=E5=B9=B2=20python3=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0455.分发饼干.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/problems/0455.分发饼干.md b/problems/0455.分发饼干.md index b3714c43..ecf7f132 100644 --- a/problems/0455.分发饼干.md +++ b/problems/0455.分发饼干.md @@ -134,7 +134,21 @@ class Solution { ``` Python: - +```python +class Solution: + def findContentChildren(self, g: List[int], s: List[int]) -> int: + #先考虑胃口小的孩子 + g.sort() + s.sort() + i=j=0 + count = 0 + while(i Date: Wed, 2 Jun 2021 23:41:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200376.=E6=91=86?= =?UTF-8?q?=E5=8A=A8=E5=BA=8F=E5=88=97=20python3=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0376.摆动序列.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md index 6fa30cde..bbca5ea0 100644 --- a/problems/0376.摆动序列.md +++ b/problems/0376.摆动序列.md @@ -138,7 +138,21 @@ class Solution { ``` Python: - +```python +class Solution: + def wiggleMaxLength(self, nums: List[int]) -> int: + #贪心 求波峰数量 + 波谷数量 + if len(nums)<=1: + return len(nums) + cur, pre = 0,0 #当前一对差值,前一对差值 + count = 1#默认最右边有一个峰值 + for i in range(len(nums)-1): + cur = nums[i+1] - nums[i] + if((cur>0 and pre<=0) or (cur<0 and pre>=0)): + count += 1 + pre = cur + return count +``` Go: