Skip to content

Commit d2b03b8

Browse files
author
xemxx
committed
Merge branch 'master' of github.com:xemxx/leetcode
2 parents 3e18076 + 689bd16 commit d2b03b8

File tree

11 files changed

+460
-2
lines changed

11 files changed

+460
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.vscode
22
done/question
33
.DS_Store
4-
.idea/*
4+
.idea/*
5+
cn

leetcode/done/算法/122.买卖股票的最佳时机-ii.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* [122] 买卖股票的最佳时机 II
55
*/
6+
package leetcode
67

78
// @lc code=start
89
func maxProfit(prices []int) int {
@@ -16,4 +17,3 @@ func maxProfit(prices []int) int {
1617
}
1718

1819
// @lc code=end
19-
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* @lc app=leetcode.cn id=334 lang=golang
3+
*
4+
* [334] 递增的三元子序列
5+
*/
6+
package leetcode
7+
8+
import "math"
9+
10+
// @lc code=start
11+
func increasingTriplet(nums []int) bool {
12+
// i, j, k := 0, 1, 2
13+
if len(nums) < 3 {
14+
return false
15+
}
16+
first, last := nums[0], math.MaxInt
17+
for _, v := range nums[1:] {
18+
if v > last {
19+
return true
20+
}
21+
if v > first {
22+
last = v
23+
} else {
24+
first = v
25+
}
26+
}
27+
return false
28+
}
29+
30+
// @lc code=end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* @lc app=leetcode.cn id=2363 lang=golang
3+
*
4+
* [2363] 合并相似的物品
5+
*/
6+
package leetcode
7+
8+
// @lc code=start
9+
func mergeSimilarItems(items1 [][]int, items2 [][]int) [][]int {
10+
keyM := make([]int, 1001)
11+
// valM := make(map[int]int)
12+
for i := range keyM {
13+
keyM[i] = -1
14+
}
15+
for _, v := range items1 {
16+
keyM[v[0]] = 0
17+
keyM[v[0]] = v[1]
18+
}
19+
for _, v := range items2 {
20+
if keyM[v[0]] == -1 {
21+
keyM[v[0]] = 0
22+
}
23+
keyM[v[0]] += v[1]
24+
}
25+
maxLen := len(items1)
26+
if len(items2) > maxLen {
27+
maxLen = len(items2)
28+
}
29+
v := make([][]int, 0, maxLen)
30+
for kk, vv := range keyM {
31+
if vv > 0 {
32+
v = append(v, []int{kk, keyM[kk]})
33+
}
34+
}
35+
return v
36+
}
37+
38+
// @lc code=end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @lc app=leetcode.cn id=2373 lang=golang
3+
*
4+
* [2373] 矩阵中的局部最大值
5+
*/
6+
7+
// @lc code=start
8+
func largestLocal(grid [][]int) [][]int {
9+
result := make([][]int, len(grid)-2)
10+
for i := 0; i < len(grid)-2; i++ {
11+
for j := 0; j < len(grid[i])-2; j++ {
12+
m := 0
13+
for k := 0; k < 3; k++ {
14+
for d := 0; d < 3; d++ {
15+
m = max(grid[i+k][j+d], m)
16+
}
17+
}
18+
if result[i] == nil {
19+
result[i] = make([]int, len(grid)-2)
20+
}
21+
result[i][j] = m
22+
}
23+
}
24+
return result
25+
26+
}
27+
28+
// @lc code=end
29+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @lc app=leetcode.cn id=392 lang=golang
3+
*
4+
* [392] 判断子序列
5+
*/
6+
7+
// @lc code=start
8+
func isSubsequence(s string, t string) bool {
9+
if len(s) == 0 {
10+
return true
11+
}
12+
if len(s) > len(t) {
13+
return false
14+
}
15+
si := 0
16+
for i := 0; i < len(t); i++ {
17+
if s[si] == t[i] {
18+
si++
19+
if si == len(s) {
20+
return true
21+
}
22+
}
23+
}
24+
return false
25+
}
26+
27+
// @lc code=end
28+

0 commit comments

Comments
 (0)