From b5c5ecf51f06b18009fe62a6450aca0cc63b0771 Mon Sep 17 00:00:00 2001 From: wjjiang <48505670+Spongecaptain@users.noreply.github.com> Date: Fri, 3 Sep 2021 19:30:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Update=200503.=E4=B8=8B=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=9B=B4=E5=A4=A7=E5=85=83=E7=B4=A0II.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 go 版本 --- problems/0503.下一个更大元素II.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/problems/0503.下一个更大元素II.md b/problems/0503.下一个更大元素II.md index 4e088ed4..624c6c7c 100644 --- a/problems/0503.下一个更大元素II.md +++ b/problems/0503.下一个更大元素II.md @@ -132,6 +132,26 @@ class Solution: return dp ``` Go: +```go +func nextGreaterElements(nums []int) []int { + length := len(nums) + result := make([]int,length,length) + for i:=0;i0&&nums[i%length]>nums[stack[len(stack)-1]]{ + index := stack[len(stack)-1] + stack = stack[:len(stack)-1] // pop + result[index] = nums[i%length] + } + stack = append(stack,i%length) + } + return result +} +``` JavaScript: From bcd03971db853fdb17d6238b6851bd989ab613dd Mon Sep 17 00:00:00 2001 From: shuwen Date: Fri, 3 Sep 2021 22:04:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=201002.=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E5=B8=B8=E7=94=A8=E5=AD=97=E7=AC=A6.md=20Python3=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8collections.Counter=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/1002.查找常用字符.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/problems/1002.查找常用字符.md b/problems/1002.查找常用字符.md index c0ca578e..e02780da 100644 --- a/problems/1002.查找常用字符.md +++ b/problems/1002.查找常用字符.md @@ -193,6 +193,26 @@ class Solution: hash[i] -= 1 return result ``` + +Python 3 使用collections.Counter +```python +class Solution: + def commonChars(self, words: List[str]) -> List[str]: + tmp = collections.Counter(words[0]) + l = [] + for i in range(1,len(words)): + # 使用 & 取交集 + tmp = tmp & collections.Counter(words[i]) + + # 剩下的就是每个单词都出现的字符(键),个数(值) + for j in tmp: + v = tmp[j] + while(v): + l.append(j) + v -= 1 + return l +``` + javaScript ```js var commonChars = function (words) {