repo
stringlengths
6
47
file_url
stringlengths
77
269
file_path
stringlengths
5
186
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-07 08:35:43
2026-01-07 08:55:24
truncated
bool
2 classes
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1105.Filling-Bookcase-Shelves/1105. Filling Bookcase Shelves.go
leetcode/1105.Filling-Bookcase-Shelves/1105. Filling Bookcase Shelves.go
package leetcode func minHeightShelves(books [][]int, shelfWidth int) int { dp := make([]int, len(books)+1) dp[0] = 0 for i := 1; i <= len(books); i++ { width, height := books[i-1][0], books[i-1][1] dp[i] = dp[i-1] + height for j := i - 1; j > 0 && width+books[j-1][0] <= shelfWidth; j-- { height = max(heig...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1105.Filling-Bookcase-Shelves/1105. Filling Bookcase Shelves_test.go
leetcode/1105.Filling-Bookcase-Shelves/1105. Filling Bookcase Shelves_test.go
package leetcode import ( "fmt" "testing" ) type question1105 struct { para1105 ans1105 } // para 是参数 // one 代表第一个参数 type para1105 struct { one [][]int w int } // ans 是答案 // one 代表第一个答案 type ans1105 struct { one int } func Test_Problem1105(t *testing.T) { qs := []question1105{ { para1105{[][]int{{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0756.Pyramid-Transition-Matrix/756. Pyramid Transition Matrix.go
leetcode/0756.Pyramid-Transition-Matrix/756. Pyramid Transition Matrix.go
package leetcode func pyramidTransition(bottom string, allowed []string) bool { pyramid := make(map[string][]string) for _, v := range allowed { pyramid[v[:len(v)-1]] = append(pyramid[v[:len(v)-1]], string(v[len(v)-1])) } return dfsT(bottom, "", pyramid) } func dfsT(bottom, above string, pyramid map[string][]st...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0756.Pyramid-Transition-Matrix/756. Pyramid Transition Matrix_test.go
leetcode/0756.Pyramid-Transition-Matrix/756. Pyramid Transition Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question756 struct { para756 ans756 } // para 是参数 // one 代表第一个参数 type para756 struct { b string a []string } // ans 是答案 // one 代表第一个答案 type ans756 struct { one bool } func Test_Problem756(t *testing.T) { qs := []question756{ { para756{"BCD", []string{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1846.Maximum-Element-After-Decreasing-and-Rearranging/1846. Maximum Element After Decreasing and Rearranging_test.go
leetcode/1846.Maximum-Element-After-Decreasing-and-Rearranging/1846. Maximum Element After Decreasing and Rearranging_test.go
package leetcode import ( "fmt" "testing" ) type question1846 struct { para1846 ans1846 } // para 是参数 // one 代表第一个参数 type para1846 struct { arr []int } // ans 是答案 // one 代表第一个答案 type ans1846 struct { one int } func Test_Problem1846(t *testing.T) { qs := []question1846{ { para1846{[]int{2, 2, 1, 2, 1}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1846.Maximum-Element-After-Decreasing-and-Rearranging/1846. Maximum Element After Decreasing and Rearranging.go
leetcode/1846.Maximum-Element-After-Decreasing-and-Rearranging/1846. Maximum Element After Decreasing and Rearranging.go
package leetcode func maximumElementAfterDecrementingAndRearranging(arr []int) int { n := len(arr) count := make([]int, n+1) for _, v := range arr { count[min(v, n)]++ } miss := 0 for _, c := range count[1:] { if c == 0 { miss++ } else { miss -= min(c-1, miss) } } return n - miss } func min(a, b...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1624.Largest-Substring-Between-Two-Equal-Characters/1624. Largest Substring Between Two Equal Characters_test.go
leetcode/1624.Largest-Substring-Between-Two-Equal-Characters/1624. Largest Substring Between Two Equal Characters_test.go
package leetcode import ( "fmt" "testing" ) type question1624 struct { para1624 ans1624 } // para 是参数 // one 代表第一个参数 type para1624 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1624 struct { one int } func Test_Problem1624(t *testing.T) { qs := []question1624{ { para1624{"aa"}, ans1624{0},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1624.Largest-Substring-Between-Two-Equal-Characters/1624. Largest Substring Between Two Equal Characters.go
leetcode/1624.Largest-Substring-Between-Two-Equal-Characters/1624. Largest Substring Between Two Equal Characters.go
package leetcode import "strings" func maxLengthBetweenEqualCharacters(s string) int { res := -1 for k, v := range s { tmp := strings.LastIndex(s, string(v)) if tmp > 0 { if res < tmp-k-1 { res = tmp - k - 1 } } } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0240.Search-a-2D-Matrix-II/240. Search a 2D Matrix II.go
leetcode/0240.Search-a-2D-Matrix-II/240. Search a 2D Matrix II.go
package leetcode // 解法一 模拟,时间复杂度 O(m+n) func searchMatrix240(matrix [][]int, target int) bool { if len(matrix) == 0 { return false } row, col := 0, len(matrix[0])-1 for col >= 0 && row <= len(matrix)-1 { if target == matrix[row][col] { return true } else if target > matrix[row][col] { row++ } else { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0240.Search-a-2D-Matrix-II/240. Search a 2D Matrix II_test.go
leetcode/0240.Search-a-2D-Matrix-II/240. Search a 2D Matrix II_test.go
package leetcode import ( "fmt" "testing" ) type question240 struct { para240 ans240 } // para 是参数 // one 代表第一个参数 type para240 struct { matrix [][]int target int } // ans 是答案 // one 代表第一个答案 type ans240 struct { one bool } func Test_Problem240(t *testing.T) { qs := []question240{ { para240{[][]int{{1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0229.Majority-Element-II/229. Majority Element II.go
leetcode/0229.Majority-Element-II/229. Majority Element II.go
package leetcode // 解法一 时间复杂度 O(n) 空间复杂度 O(1) func majorityElement229(nums []int) []int { // since we are checking if a num appears more than 1/3 of the time // it is only possible to have at most 2 nums (>1/3 + >1/3 = >2/3) count1, count2, candidate1, candidate2 := 0, 0, 0, 1 // Select Candidates for _, num := r...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0229.Majority-Element-II/229. Majority Element II_test.go
leetcode/0229.Majority-Element-II/229. Majority Element II_test.go
package leetcode import ( "fmt" "testing" ) type question229 struct { para229 ans229 } // para 是参数 // one 代表第一个参数 type para229 struct { s []int } // ans 是答案 // one 代表第一个答案 type ans229 struct { one []int } func Test_Problem229(t *testing.T) { qs := []question229{ { para229{[]int{3, 2, 3}}, ans229{[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0765.Couples-Holding-Hands/765. Couples Holding Hands_test.go
leetcode/0765.Couples-Holding-Hands/765. Couples Holding Hands_test.go
package leetcode import ( "fmt" "testing" ) type question765 struct { para765 ans765 } // para 是参数 // one 代表第一个参数 type para765 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans765 struct { one int } func Test_Problem765(t *testing.T) { qs := []question765{ { para765{[]int{0, 2, 1, 3}}, ans76...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0765.Couples-Holding-Hands/765. Couples Holding Hands.go
leetcode/0765.Couples-Holding-Hands/765. Couples Holding Hands.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) func minSwapsCouples(row []int) int { if len(row)&1 == 1 { return 0 } uf := template.UnionFind{} uf.Init(len(row)) for i := 0; i < len(row)-1; i = i + 2 { uf.Union(i, i+1) } for i := 0; i < len(row)-1; i = i + 2 { if uf.Find(row[i]) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0301.Remove-Invalid-Parentheses/301.Remove Invalid Parentheses_test.go
leetcode/0301.Remove-Invalid-Parentheses/301.Remove Invalid Parentheses_test.go
package leetcode import ( "fmt" "testing" ) type question301 struct { para301 ans301 } // s 是参数 type para301 struct { s string } // ans 是答案 type ans301 struct { ans []string } func Test_Problem301(t *testing.T) { qs := []question301{ { para301{"()())()"}, ans301{[]string{"(())()", "()()()"}}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0301.Remove-Invalid-Parentheses/301.Remove Invalid Parentheses.go
leetcode/0301.Remove-Invalid-Parentheses/301.Remove Invalid Parentheses.go
package leetcode var ( res []string mp map[string]int n int length int maxScore int str string ) func removeInvalidParentheses(s string) []string { lmoves, rmoves, lcnt, rcnt := 0, 0, 0, 0 for _, v := range s { if v == '(' { lmoves++ lcnt++ } else if v == ')' { if lmoves ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0938.Range-Sum-of-BST/938. Range Sum of BST_test.go
leetcode/0938.Range-Sum-of-BST/938. Range Sum of BST_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question938 struct { para938 ans938 } // para 是参数 // one 代表第一个参数 type para938 struct { one []int low int high int } // ans 是答案 // one 代表第一个答案 type ans938 struct { one int } func Test_Problem938(t *testing.T) {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0938.Range-Sum-of-BST/938. Range Sum of BST.go
leetcode/0938.Range-Sum-of-BST/938. Range Sum of BST.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func rangeSumBST(root *TreeNode, low int, high int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0492.Construct-the-Rectangle/492.Construct the Rectangle.go
leetcode/0492.Construct-the-Rectangle/492.Construct the Rectangle.go
package leetcode import "math" func constructRectangle(area int) []int { ans := make([]int, 2) W := int(math.Sqrt(float64(area))) for W >= 1 { if area%W == 0 { ans[0], ans[1] = area/W, W break } W -= 1 } return ans }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0492.Construct-the-Rectangle/492.Construct the Rectangle_test.go
leetcode/0492.Construct-the-Rectangle/492.Construct the Rectangle_test.go
package leetcode import ( "fmt" "testing" ) type question492 struct { para492 ans492 } // area 是参数 type para492 struct { area int } // ans 是答案 type ans492 struct { ans []int } func Test_Problem492(t *testing.T) { qs := []question492{ { para492{4}, ans492{[]int{2, 2}}, }, { para492{37}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0637.Average-of-Levels-in-Binary-Tree/637. Average of Levels in Binary Tree_test.go
leetcode/0637.Average-of-Levels-in-Binary-Tree/637. Average of Levels in Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question637 struct { para637 ans637 } // para 是参数 // one 代表第一个参数 type para637 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans637 struct { one [][]int } func Test_Problem637(t *testing.T) { qs := []questi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0637.Average-of-Levels-in-Binary-Tree/637. Average of Levels in Binary Tree.go
leetcode/0637.Average-of-Levels-in-Binary-Tree/637. Average of Levels in Binary Tree.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func averageOfLevels(root *TreeNode) []float64 { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1252.Cells-with-Odd-Values-in-a-Matrix/1252. Cells with Odd Values in a Matrix.go
leetcode/1252.Cells-with-Odd-Values-in-a-Matrix/1252. Cells with Odd Values in a Matrix.go
package leetcode // 解法一 暴力法 func oddCells(n int, m int, indices [][]int) int { matrix, res := make([][]int, n), 0 for i := range matrix { matrix[i] = make([]int, m) } for _, indice := range indices { for i := 0; i < m; i++ { matrix[indice[0]][i]++ } for j := 0; j < n; j++ { matrix[j][indice[1]]++ }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1252.Cells-with-Odd-Values-in-a-Matrix/1252. Cells with Odd Values in a Matrix_test.go
leetcode/1252.Cells-with-Odd-Values-in-a-Matrix/1252. Cells with Odd Values in a Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question1252 struct { para1252 ans1252 } // para 是参数 // one 代表第一个参数 type para1252 struct { n int m int indices [][]int } // ans 是答案 // one 代表第一个答案 type ans1252 struct { one int } func Test_Problem1252(t *testing.T) { qs := []question1252{ { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0617.Merge-Two-Binary-Trees/617. Merge Two Binary Trees.go
leetcode/0617.Merge-Two-Binary-Trees/617. Merge Two Binary Trees.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func mergeTrees(root1 *TreeNode, root2 *TreeNode) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0617.Merge-Two-Binary-Trees/617. Merge Two Binary Trees_test.go
leetcode/0617.Merge-Two-Binary-Trees/617. Merge Two Binary Trees_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question617 struct { para617 ans617 } // para 是参数 // one 代表第一个参数 type para617 struct { one []int another []int } // ans 是答案 // one 代表第一个答案 type ans617 struct { one []int } func Test_Problem617(t *testing.T) {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0345.Reverse-Vowels-of-a-String/345. Reverse Vowels of a String.go
leetcode/0345.Reverse-Vowels-of-a-String/345. Reverse Vowels of a String.go
package leetcode func reverseVowels(s string) string { b := []byte(s) for i, j := 0, len(b)-1; i < j; { if !isVowel(b[i]) { i++ continue } if !isVowel(b[j]) { j-- continue } b[i], b[j] = b[j], b[i] i++ j-- } return string(b) } func isVowel(s byte) bool { return s == 'a' || s == 'e' || s...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0345.Reverse-Vowels-of-a-String/345. Reverse Vowels of a String_test.go
leetcode/0345.Reverse-Vowels-of-a-String/345. Reverse Vowels of a String_test.go
package leetcode import ( "fmt" "testing" ) type question345 struct { para345 ans345 } // para 是参数 // one 代表第一个参数 type para345 struct { one string } // ans 是答案 // one 代表第一个答案 type ans345 struct { one string } func Test_Problem345(t *testing.T) { qs := []question345{ { para345{"hello"}, ans345{"hol...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0529.Minesweeper/529. Minesweeper.go
leetcode/0529.Minesweeper/529. Minesweeper.go
package leetcode var dir8 = [][]int{ {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, } func updateBoard(board [][]byte, click []int) [][]byte { if board[click[0]][click[1]] == 'M' { board[click[0]][click[1]] = 'X' return board } dfs(board, click[0], click[1]) return board } func...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0529.Minesweeper/529. Minesweeper_test.go
leetcode/0529.Minesweeper/529. Minesweeper_test.go
package leetcode import ( "fmt" "testing" ) type question529 struct { para529 ans529 } // para 是参数 // one 代表第一个参数 type para529 struct { b [][]byte click []int } // ans 是答案 // one 代表第一个答案 type ans529 struct { one [][]byte } func Test_Problem529(t *testing.T) { qs := []question529{ { para529{[][]b...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0414.Third-Maximum-Number/414. Third Maximum Number.go
leetcode/0414.Third-Maximum-Number/414. Third Maximum Number.go
package leetcode import ( "math" ) func thirdMax(nums []int) int { a, b, c := math.MinInt64, math.MinInt64, math.MinInt64 for _, v := range nums { if v > a { c = b b = a a = v } else if v < a && v > b { c = b b = v } else if v < b && v > c { c = v } } if c == math.MinInt64 { return a ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0414.Third-Maximum-Number/414. Third Maximum Number_test.go
leetcode/0414.Third-Maximum-Number/414. Third Maximum Number_test.go
package leetcode import ( "fmt" "testing" ) type question414 struct { para414 ans414 } // para 是参数 // one 代表第一个参数 type para414 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans414 struct { one int } func Test_Problem414(t *testing.T) { qs := []question414{ { para414{[]int{1, 1, 2}}, ans414{2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0896.Monotonic-Array/896. Monotonic Array.go
leetcode/0896.Monotonic-Array/896. Monotonic Array.go
package leetcode func isMonotonic(A []int) bool { if len(A) <= 1 { return true } if A[0] < A[1] { return inc(A[1:]) } if A[0] > A[1] { return dec(A[1:]) } return inc(A[1:]) || dec(A[1:]) } func inc(A []int) bool { for i := 0; i < len(A)-1; i++ { if A[i] > A[i+1] { return false } } return true }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0896.Monotonic-Array/896. Monotonic Array_test.go
leetcode/0896.Monotonic-Array/896. Monotonic Array_test.go
package leetcode import ( "fmt" "testing" ) type question896 struct { para896 ans896 } // para 是参数 // one 代表第一个参数 type para896 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans896 struct { one bool } func Test_Problem896(t *testing.T) { qs := []question896{ { para896{[]int{2, 1, 3}}, ans896{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1137.N-th-Tribonacci-Number/1137. N-th Tribonacci Number.go
leetcode/1137.N-th-Tribonacci-Number/1137. N-th Tribonacci Number.go
package leetcode func tribonacci(n int) int { if n < 2 { return n } trib, prev, prev2 := 1, 1, 0 for n > 2 { trib, prev, prev2 = trib+prev+prev2, trib, prev n-- } return trib }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1137.N-th-Tribonacci-Number/1137. N-th Tribonacci Number_test.go
leetcode/1137.N-th-Tribonacci-Number/1137. N-th Tribonacci Number_test.go
package leetcode import ( "fmt" "testing" ) type question1137 struct { para1137 ans1137 } // para 是参数 // one 代表第一个参数 type para1137 struct { one int } // ans 是答案 // one 代表第一个答案 type ans1137 struct { one int } func Test_Problem1137(t *testing.T) { qs := []question1137{ { para1137{1}, ans1137{1}, }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0875.Koko-Eating-Bananas/875. Koko Eating Bananas.go
leetcode/0875.Koko-Eating-Bananas/875. Koko Eating Bananas.go
package leetcode import "math" func minEatingSpeed(piles []int, H int) int { low, high := 1, maxInArr(piles) for low < high { mid := low + (high-low)>>1 if !isPossible(piles, mid, H) { low = mid + 1 } else { high = mid } } return low } func isPossible(piles []int, h, H int) bool { res := 0 for _,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0875.Koko-Eating-Bananas/875. Koko Eating Bananas_test.go
leetcode/0875.Koko-Eating-Bananas/875. Koko Eating Bananas_test.go
package leetcode import ( "fmt" "testing" ) type question875 struct { para875 ans875 } // para 是参数 // one 代表第一个参数 type para875 struct { piles []int H int } // ans 是答案 // one 代表第一个答案 type ans875 struct { one int } func Test_Problem875(t *testing.T) { qs := []question875{ { para875{[]int{3, 6, 7, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0508.Most-Frequent-Subtree-Sum/508. Most Frequent Subtree Sum.go
leetcode/0508.Most-Frequent-Subtree-Sum/508. Most Frequent Subtree Sum.go
package leetcode import ( "sort" "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ // 解法一 维护最大频次,不用排序 func findFrequentTreeS...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0508.Most-Frequent-Subtree-Sum/508. Most Frequent Subtree Sum_test.go
leetcode/0508.Most-Frequent-Subtree-Sum/508. Most Frequent Subtree Sum_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question508 struct { para508 ans508 } // para 是参数 // one 代表第一个参数 type para508 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans508 struct { one []int } func Test_Problem508(t *testing.T) { qs := []question...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1074.Number-of-Submatrices-That-Sum-to-Target/1074. Number of Submatrices That Sum to Target.go
leetcode/1074.Number-of-Submatrices-That-Sum-to-Target/1074. Number of Submatrices That Sum to Target.go
package leetcode func numSubmatrixSumTarget(matrix [][]int, target int) int { m, n, res := len(matrix), len(matrix[0]), 0 for row := range matrix { for col := 1; col < len(matrix[row]); col++ { matrix[row][col] += matrix[row][col-1] } } for i := 0; i < n; i++ { for j := i; j < n; j++ { counterMap, sum ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1074.Number-of-Submatrices-That-Sum-to-Target/1074. Number of Submatrices That Sum to Target_test.go
leetcode/1074.Number-of-Submatrices-That-Sum-to-Target/1074. Number of Submatrices That Sum to Target_test.go
package leetcode import ( "fmt" "testing" ) type question1074 struct { para1074 ans1074 } // para 是参数 // one 代表第一个参数 type para1074 struct { one [][]int t int } // ans 是答案 // one 代表第一个答案 type ans1074 struct { one int } func Test_Problem1074(t *testing.T) { qs := []question1074{ { para1074{[][]int{{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists_test.go
leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1669 struct { para1669 ans1669 } // para 是参数 // one 代表第一个参数 type para1669 struct { one []int a int b int another []int } // ans 是答案 // one 代表第一个答案 type ans1669 struct { one []int } func ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists.go
leetcode/1669.Merge-In-Between-Linked-Lists/1669. Merge In Between Linked Lists.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // ListNode define type ListNode = structures.ListNode /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func mergeInBetween(list1 *ListNode, a int, b int, list2 *ListNode) *List...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0307.Range-Sum-Query-Mutable/307. Range Sum Query - Mutable_test.go
leetcode/0307.Range-Sum-Query-Mutable/307. Range Sum Query - Mutable_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem307(t *testing.T) { obj := Constructor307([]int{1, 3, 5}) fmt.Printf("obj = %v\n", obj) fmt.Printf("SumRange(0,2) = %v\n", obj.SumRange(0, 2)) obj.Update(1, 2) fmt.Printf("obj = %v\n", obj) fmt.Printf("SumRange(0,2) = %v\n", obj.SumRange(0, 2)) ob...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0307.Range-Sum-Query-Mutable/307. Range Sum Query - Mutable.go
leetcode/0307.Range-Sum-Query-Mutable/307. Range Sum Query - Mutable.go
package leetcode import "github.com/halfrost/LeetCode-Go/template" // NumArray define type NumArray struct { st *template.SegmentTree } // Constructor307 define func Constructor307(nums []int) NumArray { st := template.SegmentTree{} st.Init(nums, func(i, j int) int { return i + j }) return NumArray{st: &st} }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
ERROR: type should be string, got "https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1287.Element-Appearing-More-Than-In-Sorted-Array/1287. Element Appearing More Than 25% In Sorted Array.go"
leetcode/1287.Element-Appearing-More-Than-In-Sorted-Array/1287. Element Appearing More Than 25% In Sorted Array.go
package leetcode func findSpecialInteger(arr []int) int { n := len(arr) for i := 0; i < n-n/4; i++ { if arr[i] == arr[i+n/4] { return arr[i] } } return -1 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
ERROR: type should be string, got "https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1287.Element-Appearing-More-Than-In-Sorted-Array/1287. Element Appearing More Than 25% In Sorted Array_test.go"
leetcode/1287.Element-Appearing-More-Than-In-Sorted-Array/1287. Element Appearing More Than 25% In Sorted Array_test.go
package leetcode import ( "fmt" "testing" ) type question1287 struct { para1287 ans1287 } // para 是参数 // one 代表第一个参数 type para1287 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1287 struct { one int } func Test_Problem1287(t *testing.T) { qs := []question1287{ { para1287{[]int{1, 2, 2, 6, 6,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1752.Check-if-Array-Is-Sorted-and-Rotated/1752. Check if Array Is Sorted and Rotated.go
leetcode/1752.Check-if-Array-Is-Sorted-and-Rotated/1752. Check if Array Is Sorted and Rotated.go
package leetcode func check(nums []int) bool { count := 0 for i := 0; i < len(nums)-1; i++ { if nums[i] > nums[i+1] { count++ if count > 1 || nums[0] < nums[len(nums)-1] { return false } } } return true }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1752.Check-if-Array-Is-Sorted-and-Rotated/1752. Check if Array Is Sorted and Rotated_test.go
leetcode/1752.Check-if-Array-Is-Sorted-and-Rotated/1752. Check if Array Is Sorted and Rotated_test.go
package leetcode import ( "fmt" "testing" ) type question1752 struct { para1752 ans1752 } // para 是参数 // one 代表第一个参数 type para1752 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1752 struct { one bool } func Test_Problem1752(t *testing.T) { qs := []question1752{ { para1752{[]int{3, 4, 5, 1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9991292.Maximum-Side-Length-of-a-Square-with-Sum-Less-than-or-Equal-to-Threshold/1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold_test.go
leetcode/9991292.Maximum-Side-Length-of-a-Square-with-Sum-Less-than-or-Equal-to-Threshold/1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold_test.go
package leetcode import ( "fmt" "testing" ) type question1292 struct { para1292 ans1292 } // para 是参数 // one 代表第一个参数 type para1292 struct { mat [][]int threshold int } // ans 是答案 // one 代表第一个答案 type ans1292 struct { one int } func Test_Problem1292(t *testing.T) { qs := []question1292{ { para12...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9991292.Maximum-Side-Length-of-a-Square-with-Sum-Less-than-or-Equal-to-Threshold/1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold.go
leetcode/9991292.Maximum-Side-Length-of-a-Square-with-Sum-Less-than-or-Equal-to-Threshold/1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold.go
package leetcode func maxSideLength(mat [][]int, threshold int) int { return 0 // m, n, sum := len(mat), len(mat[0]), make([][]int, len(mat[0])+1, len(mat[0])+1) // for i := range sum { // sum[i] = make([]int, n+1, n+1) // } // for i := 0; i < m; i++ { // for j := 0; j < n; j++ { // sum[i+1][j+1] = sum[i][...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1744.Can-You-Eat-Your-Favorite-Candy-on-Your-Favorite-Day/1744. Can You Eat Your Favorite Candy on Your Favorite Day.go
leetcode/1744.Can-You-Eat-Your-Favorite-Candy-on-Your-Favorite-Day/1744. Can You Eat Your Favorite Candy on Your Favorite Day.go
package leetcode func canEat(candiesCount []int, queries [][]int) []bool { n := len(candiesCount) prefixSum := make([]int, n) prefixSum[0] = candiesCount[0] for i := 1; i < n; i++ { prefixSum[i] = prefixSum[i-1] + candiesCount[i] } res := make([]bool, len(queries)) for i, q := range queries { favoriteType, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1744.Can-You-Eat-Your-Favorite-Candy-on-Your-Favorite-Day/1744. Can You Eat Your Favorite Candy on Your Favorite Day_test.go
leetcode/1744.Can-You-Eat-Your-Favorite-Candy-on-Your-Favorite-Day/1744. Can You Eat Your Favorite Candy on Your Favorite Day_test.go
package leetcode import ( "fmt" "testing" ) type question1744 struct { para1744 ans1744 } // para 是参数 // one 代表第一个参数 type para1744 struct { candiesCount []int queries [][]int } // ans 是答案 // one 代表第一个答案 type ans1744 struct { one []bool } func Test_Problem1744(t *testing.T) { qs := []question1744{ ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0160.Intersection-of-Two-Linked-Lists/160. Intersection of Two Linked Lists_test.go
leetcode/0160.Intersection-of-Two-Linked-Lists/160. Intersection of Two Linked Lists_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question160 struct { para160 ans160 } // para 是参数 // one 代表第一个参数 type para160 struct { one []int another []int } // ans 是答案 // one 代表第一个答案 type ans160 struct { one []int } func Test_Problem160(t *testing.T) {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0160.Intersection-of-Two-Linked-Lists/160. Intersection of Two Linked Lists.go
leetcode/0160.Intersection-of-Two-Linked-Lists/160. Intersection of Two Linked Lists.go
package leetcode import ( "fmt" "github.com/halfrost/LeetCode-Go/structures" ) // ListNode define type ListNode = structures.ListNode /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func getIntersectionNode(headA, headB *ListNode) *ListNode { //bo...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0324.Wiggle-Sort-II/324. Wiggle Sort II_test.go
leetcode/0324.Wiggle-Sort-II/324. Wiggle Sort II_test.go
package leetcode import ( "fmt" "testing" ) type question324 struct { para324 ans324 } // para 是参数 // one 代表第一个参数 type para324 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans324 struct { one []int } func Test_Problem324(t *testing.T) { qs := []question324{ { para324{[]int{}}, ans324{[]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0324.Wiggle-Sort-II/324. Wiggle Sort II.go
leetcode/0324.Wiggle-Sort-II/324. Wiggle Sort II.go
package leetcode import ( "sort" ) // 解法一 func wiggleSort(nums []int) { if len(nums) < 2 { return } median := findKthLargest324(nums, (len(nums)+1)/2) n, i, left, right := len(nums), 0, 0, len(nums)-1 for i <= right { if nums[indexMap(i, n)] > median { nums[indexMap(left, n)], nums[indexMap(i, n)] = num...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1034.Coloring-A-Border/1034.Coloring A Border.go
leetcode/1034.Coloring-A-Border/1034.Coloring A Border.go
package leetcode type point struct { x int y int } type gridInfo struct { m int n int grid [][]int originalColor int } func colorBorder(grid [][]int, row, col, color int) [][]int { m, n := len(grid), len(grid[0]) dirs := []point{{1, 0}, {-1, 0}, {0, 1}, {0, -1}} vis := make(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1034.Coloring-A-Border/1034.Coloring A Border_test.go
leetcode/1034.Coloring-A-Border/1034.Coloring A Border_test.go
package leetcode import ( "fmt" "testing" ) type question1034 struct { para1034 ans1034 } // para 是参数 type para1034 struct { grid [][]int row int col int color int } // ans 是答案 type ans1034 struct { ans [][]int } func Test_Problem1034(t *testing.T) { qs := []question1034{ { para1034{[][]int{{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0048.Rotate-Image/48. Rotate Image.go
leetcode/0048.Rotate-Image/48. Rotate Image.go
package leetcode // 解法一 func rotate(matrix [][]int) { length := len(matrix) // rotate by diagonal 对角线变换 for i := 0; i < length; i++ { for j := i + 1; j < length; j++ { matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] } } // rotate by vertical centerline 竖直轴对称翻转 for i := 0; i < length; i++ { for j...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0048.Rotate-Image/48. Rotate Image_test.go
leetcode/0048.Rotate-Image/48. Rotate Image_test.go
package leetcode import ( "fmt" "testing" ) type question48 struct { para48 ans48 } // para 是参数 // one 代表第一个参数 type para48 struct { s [][]int } // ans 是答案 // one 代表第一个答案 type ans48 struct { s [][]int } func Test_Problem48(t *testing.T) { qs := []question48{ { para48{[][]int{{1, 2, 3}, {4, 5, 6}, {7, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1089.Duplicate-Zeros/1089. Duplicate Zeros.go
leetcode/1089.Duplicate-Zeros/1089. Duplicate Zeros.go
package leetcode func duplicateZeros(arr []int) { for i := 0; i < len(arr); i++ { if arr[i] == 0 && i+1 < len(arr) { arr = append(arr[:i+1], arr[i:len(arr)-1]...) i++ } } }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1089.Duplicate-Zeros/1089. Duplicate Zeros_test.go
leetcode/1089.Duplicate-Zeros/1089. Duplicate Zeros_test.go
package leetcode import ( "fmt" "testing" ) type question1089 struct { para1089 ans1089 } // para 是参数 // one 代表第一个参数 type para1089 struct { arr []int } // ans 是答案 // one 代表第一个答案 type ans1089 struct { } func Test_Problem1089(t *testing.T) { qs := []question1089{ { para1089{[]int{1, 0, 0, 1, 1, 1, 1, 0,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1002.Find-Common-Characters/1002. Find Common Characters_test.go
leetcode/1002.Find-Common-Characters/1002. Find Common Characters_test.go
package leetcode import ( "fmt" "testing" ) type question1002 struct { para1002 ans1002 } // para 是参数 // one 代表第一个参数 type para1002 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans1002 struct { one []string } func Test_Problem1002(t *testing.T) { qs := []question1002{ { para1002{[]string{"be...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1002.Find-Common-Characters/1002. Find Common Characters.go
leetcode/1002.Find-Common-Characters/1002. Find Common Characters.go
package leetcode import "math" func commonChars(A []string) []string { cnt := [26]int{} for i := range cnt { cnt[i] = math.MaxUint16 } cntInWord := [26]int{} for _, word := range A { for _, char := range []byte(word) { // compiler trick - here we will not allocate new memory cntInWord[char-'a']++ } fo...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0007.Reverse-Integer/7. Reverse Integer_test.go
leetcode/0007.Reverse-Integer/7. Reverse Integer_test.go
package leetcode import ( "fmt" "testing" ) type question7 struct { para7 ans7 } // para 是参数 // one 代表第一个参数 type para7 struct { one int } // ans 是答案 // one 代表第一个答案 type ans7 struct { one int } func Test_Problem7(t *testing.T) { qs := []question7{ { para7{321}, ans7{123}, }, { para7{-123}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0007.Reverse-Integer/7. Reverse Integer.go
leetcode/0007.Reverse-Integer/7. Reverse Integer.go
package leetcode func reverse7(x int) int { tmp := 0 for x != 0 { tmp = tmp*10 + x%10 x = x / 10 } if tmp > 1<<31-1 || tmp < -(1<<31) { return 0 } return tmp }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0927.Three-Equal-Parts/927. Three Equal Parts_test.go
leetcode/0927.Three-Equal-Parts/927. Three Equal Parts_test.go
package leetcode import ( "fmt" "testing" ) type question927 struct { para927 ans927 } // para 是参数 // one 代表第一个参数 type para927 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans927 struct { one []int } func Test_Problem927(t *testing.T) { qs := []question927{ { para927{[]int{1, 0, 1, 0, 1}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0927.Three-Equal-Parts/927. Three Equal Parts.go
leetcode/0927.Three-Equal-Parts/927. Three Equal Parts.go
package leetcode func threeEqualParts(A []int) []int { n, ones, i, count := len(A), 0, 0, 0 for _, a := range A { ones += a } if ones == 0 { return []int{0, n - 1} } if ones%3 != 0 { return []int{-1, -1} } k := ones / 3 for i < n { if A[i] == 1 { break } i++ } start, j := i, i for j < n { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament.go
leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament.go
package leetcode // 解法一 func numberOfMatches(n int) int { return n - 1 } // 解法二 模拟 func numberOfMatches1(n int) int { sum := 0 for n != 1 { if n&1 == 0 { sum += n / 2 n = n / 2 } else { sum += (n - 1) / 2 n = (n-1)/2 + 1 } } return sum }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament_test.go
leetcode/1688.Count-of-Matches-in-Tournament/1688. Count of Matches in Tournament_test.go
package leetcode import ( "fmt" "testing" ) type question1688 struct { para1688 ans1688 } // para 是参数 // one 代表第一个参数 type para1688 struct { n int } // ans 是答案 // one 代表第一个答案 type ans1688 struct { one int } func Test_Problem1688(t *testing.T) { qs := []question1688{ { para1688{7}, ans1688{6}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0495.Teemo-Attacking/495.Teemo Attacking.go
leetcode/0495.Teemo-Attacking/495.Teemo Attacking.go
package leetcode func findPoisonedDuration(timeSeries []int, duration int) int { var ans int for i := 1; i < len(timeSeries); i++ { t := timeSeries[i-1] end := t + duration - 1 if end < timeSeries[i] { ans += duration } else { ans += timeSeries[i] - t } } ans += duration return ans }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0495.Teemo-Attacking/495.Teemo Attacking_test.go
leetcode/0495.Teemo-Attacking/495.Teemo Attacking_test.go
package leetcode import ( "fmt" "testing" ) type question495 struct { para495 ans495 } // para 是参数 type para495 struct { timeSeries []int duration int } // ans 是答案 type ans495 struct { ans int } func Test_Problem495(t *testing.T) { qs := []question495{ { para495{[]int{1, 4}, 2}, ans495{4}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0121.Best-Time-to-Buy-and-Sell-Stock/121. Best Time to Buy and Sell Stock.go
leetcode/0121.Best-Time-to-Buy-and-Sell-Stock/121. Best Time to Buy and Sell Stock.go
package leetcode // 解法一 模拟 DP func maxProfit(prices []int) int { if len(prices) < 1 { return 0 } min, maxProfit := prices[0], 0 for i := 1; i < len(prices); i++ { if prices[i]-min > maxProfit { maxProfit = prices[i] - min } if prices[i] < min { min = prices[i] } } return maxProfit } // 解法二 单调栈 f...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0121.Best-Time-to-Buy-and-Sell-Stock/121. Best Time to Buy and Sell Stock_test.go
leetcode/0121.Best-Time-to-Buy-and-Sell-Stock/121. Best Time to Buy and Sell Stock_test.go
package leetcode import ( "fmt" "testing" ) type question121 struct { para121 ans121 } // para 是参数 // one 代表第一个参数 type para121 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans121 struct { one int } func Test_Problem121(t *testing.T) { qs := []question121{ { para121{[]int{}}, ans121{0}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0026.Remove-Duplicates-from-Sorted-Array/26. Remove Duplicates from Sorted Array.go
leetcode/0026.Remove-Duplicates-from-Sorted-Array/26. Remove Duplicates from Sorted Array.go
package leetcode // 解法一 func removeDuplicates(nums []int) int { if len(nums) == 0 { return 0 } last, finder := 0, 0 for last < len(nums)-1 { for nums[finder] == nums[last] { finder++ if finder == len(nums) { return last + 1 } } nums[last+1] = nums[finder] last++ } return last + 1 } // 解法二...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0026.Remove-Duplicates-from-Sorted-Array/26. Remove Duplicates from Sorted Array_test.go
leetcode/0026.Remove-Duplicates-from-Sorted-Array/26. Remove Duplicates from Sorted Array_test.go
package leetcode import ( "fmt" "testing" ) type question26 struct { para26 ans26 } // para 是参数 // one 代表第一个参数 type para26 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans26 struct { one int } func Test_Problem26(t *testing.T) { qs := []question26{ { para26{[]int{1, 1, 2}}, ans26{2}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0538.Convert-BST-to-Greater-Tree/538. Convert BST to Greater Tree.go
leetcode/0538.Convert-BST-to-Greater-Tree/538. Convert BST to Greater Tree.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func convertBST(root *TreeNode) *TreeNode { if ro...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0538.Convert-BST-to-Greater-Tree/538. Convert BST to Greater Tree_test.go
leetcode/0538.Convert-BST-to-Greater-Tree/538. Convert BST to Greater Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question538 struct { para538 ans538 } // para 是参数 // one 代表第一个参数 type para538 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans538 struct { one []int } func Test_Problem538(t *testing.T) { qs := []question...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0638.Shopping-Offers/638. Shopping Offers.go
leetcode/0638.Shopping-Offers/638. Shopping Offers.go
package leetcode func shoppingOffers(price []int, special [][]int, needs []int) int { res := -1 dfsShoppingOffers(price, special, needs, 0, &res) return res } func dfsShoppingOffers(price []int, special [][]int, needs []int, pay int, res *int) { noNeeds := true // 剪枝 for _, need := range needs { if need < 0 {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0638.Shopping-Offers/638. Shopping Offers_test.go
leetcode/0638.Shopping-Offers/638. Shopping Offers_test.go
package leetcode import ( "fmt" "testing" ) type question638 struct { para638 ans638 } // para 是参数 // one 代表第一个参数 type para638 struct { price []int special [][]int needs []int } // ans 是答案 // one 代表第一个答案 type ans638 struct { one int } func Test_Problem638(t *testing.T) { qs := []question638{ { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0518.Coin-Change-II/518. Coin Change II_test.go
leetcode/0518.Coin-Change-II/518. Coin Change II_test.go
package leetcode import ( "fmt" "testing" ) type question518 struct { para518 ans518 } // para 是参数 // one 代表第一个参数 type para518 struct { amount int coins []int } // ans 是答案 // one 代表第一个答案 type ans518 struct { one int } func Test_Problem518(t *testing.T) { qs := []question518{ { para518{5, []int{1, 2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0518.Coin-Change-II/518. Coin Change II.go
leetcode/0518.Coin-Change-II/518. Coin Change II.go
package leetcode func change(amount int, coins []int) int { dp := make([]int, amount+1) dp[0] = 1 for _, coin := range coins { for i := coin; i <= amount; i++ { dp[i] += dp[i-coin] } } return dp[amount] }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0122.Best-Time-to-Buy-and-Sell-Stock-II/122. Best Time to Buy and Sell Stock II_test.go
leetcode/0122.Best-Time-to-Buy-and-Sell-Stock-II/122. Best Time to Buy and Sell Stock II_test.go
package leetcode import ( "fmt" "testing" ) type question122 struct { para122 ans122 } // para 是参数 // one 代表第一个参数 type para122 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans122 struct { one int } func Test_Problem122(t *testing.T) { qs := []question122{ { para122{[]int{}}, ans122{0}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0122.Best-Time-to-Buy-and-Sell-Stock-II/122. Best Time to Buy and Sell Stock II.go
leetcode/0122.Best-Time-to-Buy-and-Sell-Stock-II/122. Best Time to Buy and Sell Stock II.go
package leetcode func maxProfit122(prices []int) int { profit := 0 for i := 0; i < len(prices)-1; i++ { if prices[i+1] > prices[i] { profit += prices[i+1] - prices[i] } } return profit }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1079.Letter-Tile-Possibilities/1079. Letter Tile Possibilities_test.go
leetcode/1079.Letter-Tile-Possibilities/1079. Letter Tile Possibilities_test.go
package leetcode import ( "fmt" "testing" ) type question1079 struct { para1079 ans1079 } // para 是参数 // one 代表第一个参数 type para1079 struct { one string } // ans 是答案 // one 代表第一个答案 type ans1079 struct { one int } func Test_Problem1079(t *testing.T) { qs := []question1079{ { para1079{"AAB"}, ans1079{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1079.Letter-Tile-Possibilities/1079. Letter Tile Possibilities.go
leetcode/1079.Letter-Tile-Possibilities/1079. Letter Tile Possibilities.go
package leetcode // 解法一 DFS func numTilePossibilities(tiles string) int { m := make(map[byte]int) for i := range tiles { m[tiles[i]]++ } arr := make([]int, 0) for _, v := range m { arr = append(arr, v) } return numTileDFS(arr) } func numTileDFS(arr []int) (r int) { for i := 0; i < len(arr); i++ { if arr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1700.Number-of-Students-Unable-to-Eat-Lunch/1700. Number of Students Unable to Eat Lunch.go
leetcode/1700.Number-of-Students-Unable-to-Eat-Lunch/1700. Number of Students Unable to Eat Lunch.go
package leetcode func countStudents(students []int, sandwiches []int) int { tmp, n, i := [2]int{}, len(students), 0 for _, v := range students { tmp[v]++ } for i < n && tmp[sandwiches[i]] > 0 { tmp[sandwiches[i]]-- i++ } return n - i }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1700.Number-of-Students-Unable-to-Eat-Lunch/1700. Number of Students Unable to Eat Lunch_test.go
leetcode/1700.Number-of-Students-Unable-to-Eat-Lunch/1700. Number of Students Unable to Eat Lunch_test.go
package leetcode import ( "fmt" "testing" ) type question1700 struct { para1700 ans1700 } // para 是参数 // one 代表第一个参数 type para1700 struct { students []int sandwiches []int } // ans 是答案 // one 代表第一个答案 type ans1700 struct { one int } func Test_Problem1700(t *testing.T) { qs := []question1700{ { para...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer/1281. Subtract the Product and Sum of Digits of an Integer.go
leetcode/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer/1281. Subtract the Product and Sum of Digits of an Integer.go
package leetcode func subtractProductAndSum(n int) int { sum, product := 0, 1 for ; n > 0; n /= 10 { sum += n % 10 product *= n % 10 } return product - sum }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer/1281. Subtract the Product and Sum of Digits of an Integer_test.go
leetcode/1281.Subtract-the-Product-and-Sum-of-Digits-of-an-Integer/1281. Subtract the Product and Sum of Digits of an Integer_test.go
package leetcode import ( "fmt" "testing" ) type question1281 struct { para1281 ans1281 } // para 是参数 // one 代表第一个参数 type para1281 struct { n int } // ans 是答案 // one 代表第一个答案 type ans1281 struct { one int } func Test_Problem1281(t *testing.T) { qs := []question1281{ { para1281{234}, ans1281{15}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0239.Sliding-Window-Maximum/239. Sliding Window Maximum.go
leetcode/0239.Sliding-Window-Maximum/239. Sliding Window Maximum.go
package leetcode // 解法一 暴力解法 O(nk) func maxSlidingWindow1(a []int, k int) []int { res := make([]int, 0, k) n := len(a) if n == 0 { return []int{} } for i := 0; i <= n-k; i++ { max := a[i] for j := 1; j < k; j++ { if max < a[i+j] { max = a[i+j] } } res = append(res, max) } return res } // 解...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0239.Sliding-Window-Maximum/239. Sliding Window Maximum_test.go
leetcode/0239.Sliding-Window-Maximum/239. Sliding Window Maximum_test.go
package leetcode import ( "fmt" "testing" ) type question239 struct { para239 ans239 } // para 是参数 // one 代表第一个参数 type para239 struct { one []int k int } // ans 是答案 // one 代表第一个答案 type ans239 struct { one []int } func Test_Problem239(t *testing.T) { qs := []question239{ { para239{[]int{1, 3, -1, -...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1021.Remove-Outermost-Parentheses/1021. Remove Outermost Parentheses.go
leetcode/1021.Remove-Outermost-Parentheses/1021. Remove Outermost Parentheses.go
package leetcode // 解法一 func removeOuterParentheses(S string) string { now, current, ans := 0, "", "" for _, char := range S { if string(char) == "(" { now++ } else if string(char) == ")" { now-- } current += string(char) if now == 0 { ans += current[1 : len(current)-1] current = "" } } ret...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1021.Remove-Outermost-Parentheses/1021. Remove Outermost Parentheses_test.go
leetcode/1021.Remove-Outermost-Parentheses/1021. Remove Outermost Parentheses_test.go
package leetcode import ( "fmt" "testing" ) type question1021 struct { para1021 ans1021 } // para 是参数 // one 代表第一个参数 type para1021 struct { one string } // ans 是答案 // one 代表第一个答案 type ans1021 struct { one string } func Test_Problem1021(t *testing.T) { qs := []question1021{ { para1021{"(()())(())"}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0115.Distinct-Subsequences/115. Distinct Subsequences_test.go
leetcode/0115.Distinct-Subsequences/115. Distinct Subsequences_test.go
package leetcode import ( "fmt" "testing" ) type question115 struct { para115 ans115 } // para 是参数 // one 代表第一个参数 type para115 struct { s string t string } // ans 是答案 // one 代表第一个答案 type ans115 struct { one int } func Test_Problem115(t *testing.T) { qs := []question115{ { para115{"rabbbit", "rabbit"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0115.Distinct-Subsequences/115. Distinct Subsequences.go
leetcode/0115.Distinct-Subsequences/115. Distinct Subsequences.go
package leetcode // 解法一 压缩版 DP func numDistinct(s string, t string) int { dp := make([]int, len(s)+1) for i, curT := range t { pre := 0 for j, curS := range s { if i == 0 { pre = 1 } newDP := dp[j+1] if curT == curS { dp[j+1] = dp[j] + pre } else { dp[j+1] = dp[j] } pre = newDP ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0662.Maximum-Width-of-Binary-Tree/662. Maximum Width of Binary Tree_test.go
leetcode/0662.Maximum-Width-of-Binary-Tree/662. Maximum Width of Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question662 struct { para662 ans662 } // para 是参数 // one 代表第一个参数 type para662 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans662 struct { one int } func Test_Problem662(t *testing.T) { qs := []question66...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0662.Maximum-Width-of-Binary-Tree/662. Maximum Width of Binary Tree.go
leetcode/0662.Maximum-Width-of-Binary-Tree/662. Maximum Width of Binary Tree.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func widthOfBinaryTree(root *TreeNode) int { if r...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false