mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Merge branch 'youngyangyang04:master' into master
This commit is contained in:
@ -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;i<len(result);i++{
|
||||
result[i] = -1
|
||||
}
|
||||
//单调递减,存储数组下标索引
|
||||
stack := make([]int,0)
|
||||
for i:=0;i<length*2;i++{
|
||||
for len(stack)>0&&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:
|
||||
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user