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/0200.Number-of-Islands/200. Number of Islands_test.go
leetcode/0200.Number-of-Islands/200. Number of Islands_test.go
package leetcode import ( "fmt" "testing" ) type question200 struct { para200 ans200 } // para 是参数 // one 代表第一个参数 type para200 struct { one [][]byte } // ans 是答案 // one 代表第一个答案 type ans200 struct { one int } func Test_Problem200(t *testing.T) { qs := []question200{ { para200{[][]byte{ {'1', '1', ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0200.Number-of-Islands/200. Number of Islands.go
leetcode/0200.Number-of-Islands/200. Number of Islands.go
package leetcode var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } func numIslands(grid [][]byte) int { m := len(grid) if m == 0 { return 0 } n := len(grid[0]) if n == 0 { return 0 } res, visited := 0, make([][]bool, m) for i := 0; i < m; i++ { visited[i] = make([]bool, n) } for i := 0; i < m...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0744.Find-Smallest-Letter-Greater-Than-Target/744. Find Smallest Letter Greater Than Target.go
leetcode/0744.Find-Smallest-Letter-Greater-Than-Target/744. Find Smallest Letter Greater Than Target.go
package leetcode func nextGreatestLetter(letters []byte, target byte) byte { low, high := 0, len(letters)-1 for low <= high { mid := low + (high-low)>>1 if letters[mid] > target { high = mid - 1 } else { low = mid + 1 } } find := letters[low%len(letters)] if find <= target { return letters[0] } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0744.Find-Smallest-Letter-Greater-Than-Target/744. Find Smallest Letter Greater Than Target_test.go
leetcode/0744.Find-Smallest-Letter-Greater-Than-Target/744. Find Smallest Letter Greater Than Target_test.go
package leetcode import ( "fmt" "testing" ) type question744 struct { para744 ans744 } // para 是参数 // one 代表第一个参数 type para744 struct { letters []byte target byte } // ans 是答案 // one 代表第一个答案 type ans744 struct { one byte } func Test_Problem744(t *testing.T) { qs := []question744{ { para744{[]byte{'...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1609.Even-Odd-Tree/1609.Even Odd Tree.go
leetcode/1609.Even-Odd-Tree/1609.Even Odd Tree.go
package leetcode type TreeNode struct { Val int Left *TreeNode Right *TreeNode } func isEvenOddTree(root *TreeNode) bool { level := 0 queue := []*TreeNode{root} for len(queue) != 0 { length := len(queue) var nums []int for i := 0; i < length; i++ { node := queue[i] if node.Left != nil { queue...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1609.Even-Odd-Tree/1609.Even Odd Tree_test.go
leetcode/1609.Even-Odd-Tree/1609.Even Odd Tree_test.go
package leetcode import ( "fmt" "testing" ) type question1609 struct { para1609 ans1609 } // para 是参数 type para1609 struct { root *TreeNode } // ans 是答案 type ans1609 struct { ans bool } func Test_Problem1609(t *testing.T) { qs := []question1609{ { para1609{&TreeNode{1, &TreeNode{10, &TreeNod...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0923.3Sum-With-Multiplicity/923. 3Sum With Multiplicity_test.go
leetcode/0923.3Sum-With-Multiplicity/923. 3Sum With Multiplicity_test.go
package leetcode import ( "fmt" "testing" ) type question923 struct { para923 ans923 } // para 是参数 // one 代表第一个参数 type para923 struct { a []int t int } // ans 是答案 // one 代表第一个答案 type ans923 struct { one int } func Test_Problem923(t *testing.T) { qs := []question923{ { para923{[]int{1, 1, 2, 2, 3, 3,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0923.3Sum-With-Multiplicity/923. 3Sum With Multiplicity.go
leetcode/0923.3Sum-With-Multiplicity/923. 3Sum With Multiplicity.go
package leetcode import ( "sort" ) func threeSumMulti(A []int, target int) int { mod := 1000000007 counter := map[int]int{} for _, value := range A { counter[value]++ } uniqNums := []int{} for key := range counter { uniqNums = append(uniqNums, key) } sort.Ints(uniqNums) res := 0 for i := 0; i < len(u...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1266.Minimum-Time-Visiting-All-Points/1266. Minimum Time Visiting All Points_test.go
leetcode/1266.Minimum-Time-Visiting-All-Points/1266. Minimum Time Visiting All Points_test.go
package leetcode import ( "fmt" "testing" ) type question1266 struct { para1266 ans1266 } // para 是参数 // one 代表第一个参数 type para1266 struct { points [][]int } // ans 是答案 // one 代表第一个答案 type ans1266 struct { one int } func Test_Problem1266(t *testing.T) { qs := []question1266{ { para1266{[][]int{{1, 1},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1266.Minimum-Time-Visiting-All-Points/1266. Minimum Time Visiting All Points.go
leetcode/1266.Minimum-Time-Visiting-All-Points/1266. Minimum Time Visiting All Points.go
package leetcode func minTimeToVisitAllPoints(points [][]int) int { res := 0 for i := 1; i < len(points); i++ { res += max(abs(points[i][0]-points[i-1][0]), abs(points[i][1]-points[i-1][1])) } return res } func max(a int, b int) int { if a > b { return a } return b } func abs(a int) int { if a > 0 { re...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0060.Permutation-Sequence/60. Permutation Sequence_test.go
leetcode/0060.Permutation-Sequence/60. Permutation Sequence_test.go
package leetcode import ( "fmt" "testing" ) type question60 struct { para60 ans60 } // para 是参数 // one 代表第一个参数 type para60 struct { n int k int } // ans 是答案 // one 代表第一个答案 type ans60 struct { one string } func Test_Problem60(t *testing.T) { qs := []question60{ { para60{3, 3}, ans60{"213"}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0060.Permutation-Sequence/60. Permutation Sequence.go
leetcode/0060.Permutation-Sequence/60. Permutation Sequence.go
package leetcode import ( "fmt" "strconv" ) func getPermutation(n int, k int) string { if k == 0 { return "" } used, p, res := make([]bool, n), []int{}, "" findPermutation(n, 0, &k, p, &res, &used) return res } func findPermutation(n, index int, k *int, p []int, res *string, used *[]bool) { fmt.Printf("n =...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0910.Smallest-Range-II/910.Smallest Range II_test.go
leetcode/0910.Smallest-Range-II/910.Smallest Range II_test.go
package leetcode import ( "fmt" "testing" ) type question910 struct { para910 ans910 } type para910 struct { A []int K int } type ans910 struct { one int } // Test_Problem910 ... func Test_Problem910(t *testing.T) { qs := []question910{ { para910{[]int{1}, 0}, ans910{0}, }, { para910{[]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0910.Smallest-Range-II/910.Smallest Range II.go
leetcode/0910.Smallest-Range-II/910.Smallest Range II.go
package leetcode import "sort" func smallestRangeII(A []int, K int) int { n := len(A) sort.Ints(A) res := A[n-1] - A[0] for i := 0; i < n-1; i++ { a, b := A[i], A[i+1] high := max(A[n-1]-K, a+K) low := min(A[0]+K, b-K) res = min(res, high-low) } return res } func max(a, b int) int { if a > b { retur...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0137.Single-Number-II/137. Single Number II_test.go
leetcode/0137.Single-Number-II/137. Single Number II_test.go
package leetcode import ( "fmt" "testing" ) type question137 struct { para137 ans137 } // para 是参数 // one 代表第一个参数 type para137 struct { s []int } // ans 是答案 // one 代表第一个答案 type ans137 struct { one int } func Test_Problem137(t *testing.T) { qs := []question137{ { para137{[]int{2, 2, 3, 2}}, ans137{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0137.Single-Number-II/137. Single Number II.go
leetcode/0137.Single-Number-II/137. Single Number II.go
package leetcode func singleNumberII(nums []int) int { ones, twos := 0, 0 for i := 0; i < len(nums); i++ { ones = (ones ^ nums[i]) & ^twos twos = (twos ^ nums[i]) & ^ones } return ones } // 以下是拓展题 // 在数组中每个元素都出现 5 次,找出只出现 1 次的数。 // 解法一 func singleNumberIIIII(nums []int) int { na, nb, nc := 0, 0, 0 for i :=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0423.Reconstruct-Original-Digits-from-English/423. Reconstruct Original Digits from English.go
leetcode/0423.Reconstruct-Original-Digits-from-English/423. Reconstruct Original Digits from English.go
package leetcode import ( "strings" ) func originalDigits(s string) string { digits := make([]int, 26) for i := 0; i < len(s); i++ { digits[int(s[i]-'a')]++ } res := make([]string, 10) res[0] = convert('z', digits, "zero", "0") res[6] = convert('x', digits, "six", "6") res[2] = convert('w', digits, "two", "...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0423.Reconstruct-Original-Digits-from-English/423. Reconstruct Original Digits from English_test.go
leetcode/0423.Reconstruct-Original-Digits-from-English/423. Reconstruct Original Digits from English_test.go
package leetcode import ( "fmt" "testing" ) type question423 struct { para423 ans423 } // para 是参数 // one 代表第一个参数 type para423 struct { one string } // ans 是答案 // one 代表第一个答案 type ans423 struct { one int } func Test_Problem423(t *testing.T) { qs := []question423{ { para423{"owoztneoer"}, ans423{01...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite_test.go
leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite_test.go
package leetcode import ( "fmt" "testing" ) type question785 struct { para785 ans785 } // para 是参数 // one 代表第一个参数 type para785 struct { graph [][]int } // ans 是答案 // one 代表第一个答案 type ans785 struct { one bool } func Test_Problem785(t *testing.T) { qs := []question785{ { para785{[][]int{{1, 3}, {0, 2},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite.go
leetcode/0785.Is-Graph-Bipartite/785. Is Graph Bipartite.go
package leetcode // DFS 染色,1 是红色,0 是绿色,-1 是未染色 func isBipartite(graph [][]int) bool { colors := make([]int, len(graph)) for i := range colors { colors[i] = -1 } for i := range graph { if !dfs(i, graph, colors, -1) { return false } } return true } func dfs(n int, graph [][]int, colors []int, parentCol i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0669.Trim-a-Binary-Search-Tree/669. Trim a Binary Search Tree.go
leetcode/0669.Trim-a-Binary-Search-Tree/669. Trim a Binary Search 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 trimBST(root *TreeNode, low int, high int) *T...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0669.Trim-a-Binary-Search-Tree/669. Trim a Binary Search Tree_test.go
leetcode/0669.Trim-a-Binary-Search-Tree/669. Trim a Binary Search Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question669 struct { para669 ans669 } // para 是参数 // one 代表第一个参数 type para669 struct { one []int low int high int } // ans 是答案 // one 代表第一个答案 type ans669 struct { one []int } func Test_Problem669(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/0409.Longest-Palindrome/409. Longest Palindrome_test.go
leetcode/0409.Longest-Palindrome/409. Longest Palindrome_test.go
package leetcode import ( "fmt" "testing" ) type question409 struct { para409 ans409 } // para 是参数 // one 代表第一个参数 type para409 struct { one string } // ans 是答案 // one 代表第一个答案 type ans409 struct { one int } func Test_Problem409(t *testing.T) { qs := []question409{ { para409{"abccccdd"}, ans409{7}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0409.Longest-Palindrome/409. Longest Palindrome.go
leetcode/0409.Longest-Palindrome/409. Longest Palindrome.go
package leetcode func longestPalindrome(s string) int { counter := make(map[rune]int) for _, r := range s { counter[r]++ } answer := 0 for _, v := range counter { answer += v / 2 * 2 if answer%2 == 0 && v%2 == 1 { answer++ } } return answer }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0543.Diameter-of-Binary-Tree/543. Diameter of Binary Tree_test.go
leetcode/0543.Diameter-of-Binary-Tree/543. Diameter of Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question543 struct { para543 ans543 } // para 是参数 // one 代表第一个参数 type para543 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans543 struct { one int } func Test_Problem543(t *testing.T) { qs := []question54...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0543.Diameter-of-Binary-Tree/543. Diameter of Binary Tree.go
leetcode/0543.Diameter-of-Binary-Tree/543. Diameter 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 diameterOfBinaryTree(root *TreeNode) int { r...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0695.Max-Area-of-Island/695. Max Area of Island.go
leetcode/0695.Max-Area-of-Island/695. Max Area of Island.go
package leetcode var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } func maxAreaOfIsland(grid [][]int) int { res := 0 for i, row := range grid { for j, col := range row { if col == 0 { continue } area := areaOfIsland(grid, i, j) if area > res { res = area } } } return res } fun...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0695.Max-Area-of-Island/695. Max Area of Island_test.go
leetcode/0695.Max-Area-of-Island/695. Max Area of Island_test.go
package leetcode import ( "fmt" "testing" ) type question695 struct { para695 ans695 } // para 是参数 // one 代表第一个参数 type para695 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans695 struct { one int } func Test_Problem695(t *testing.T) { qs := []question695{ { para695{[][]int{ {1, 1, 1, 1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0877.Stone-Game/877. Stone Game.go
leetcode/0877.Stone-Game/877. Stone Game.go
package leetcode func stoneGame(piles []int) bool { return true }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0877.Stone-Game/877. Stone Game_test.go
leetcode/0877.Stone-Game/877. Stone Game_test.go
package leetcode import ( "fmt" "testing" ) type question877 struct { para877 ans877 } // para 是参数 // one 代表第一个参数 type para877 struct { piles []int } // ans 是答案 // one 代表第一个答案 type ans877 struct { one bool } func Test_Problem877(t *testing.T) { qs := []question877{ { para877{[]int{5, 3, 4, 5}}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1037.Valid-Boomerang/1037. Valid Boomerang_test.go
leetcode/1037.Valid-Boomerang/1037. Valid Boomerang_test.go
package leetcode import ( "fmt" "testing" ) type question1037 struct { para1037 ans1037 } // para 是参数 // one 代表第一个参数 type para1037 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans1037 struct { one bool } func Test_Problem1037(t *testing.T) { qs := []question1037{ { para1037{[][]int{{1, 2}, {2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1037.Valid-Boomerang/1037. Valid Boomerang.go
leetcode/1037.Valid-Boomerang/1037. Valid Boomerang.go
package leetcode func isBoomerang(points [][]int) bool { return (points[0][0]-points[1][0])*(points[0][1]-points[2][1]) != (points[0][0]-points[2][0])*(points[0][1]-points[1][1]) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1030.Matrix-Cells-in-Distance-Order/1030. Matrix Cells in Distance Order_test.go
leetcode/1030.Matrix-Cells-in-Distance-Order/1030. Matrix Cells in Distance Order_test.go
package leetcode import ( "fmt" "testing" ) type question1030 struct { para1030 ans1030 } // para 是参数 // one 代表第一个参数 type para1030 struct { R int C int r0 int c0 int } // ans 是答案 // one 代表第一个答案 type ans1030 struct { one [][]int } func Test_Problem1030(t *testing.T) { qs := []question1030{ { para...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1030.Matrix-Cells-in-Distance-Order/1030. Matrix Cells in Distance Order.go
leetcode/1030.Matrix-Cells-in-Distance-Order/1030. Matrix Cells in Distance Order.go
package leetcode func allCellsDistOrder(R int, C int, r0 int, c0 int) [][]int { longRow, longCol, result := max(abs(r0-0), abs(R-r0)), max(abs(c0-0), abs(C-c0)), make([][]int, 0) maxDistance := longRow + longCol bucket := make([][][]int, maxDistance+1) for i := 0; i <= maxDistance; i++ { bucket[i] = make([][]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1040.Moving-Stones-Until-Consecutive-II/1040. Moving Stones Until Consecutive II_test.go
leetcode/1040.Moving-Stones-Until-Consecutive-II/1040. Moving Stones Until Consecutive II_test.go
package leetcode import ( "fmt" "testing" ) type question1040 struct { para1040 ans1040 } // para 是参数 // one 代表第一个参数 type para1040 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1040 struct { one []int } func Test_Problem1040(t *testing.T) { qs := []question1040{ { para1040{[]int{7, 4, 9}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1040.Moving-Stones-Until-Consecutive-II/1040. Moving Stones Until Consecutive II.go
leetcode/1040.Moving-Stones-Until-Consecutive-II/1040. Moving Stones Until Consecutive II.go
package leetcode import ( "math" "sort" ) func numMovesStonesII(stones []int) []int { if len(stones) == 0 { return []int{0, 0} } sort.Ints(stones) n := len(stones) maxStep, minStep, left, right := max(stones[n-1]-stones[1]-n+2, stones[n-2]-stones[0]-n+2), math.MaxInt64, 0, 0 for left < n { if right+1 < n ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0541.Reverse-String-II/541. Reverse String II.go
leetcode/0541.Reverse-String-II/541. Reverse String II.go
package leetcode func reverseStr(s string, k int) string { if k > len(s) { k = len(s) } for i := 0; i < len(s); i = i + 2*k { if len(s)-i >= k { ss := revers(s[i : i+k]) s = s[:i] + ss + s[i+k:] } else { ss := revers(s[i:]) s = s[:i] + ss } } return s } func revers(s string) string { bytes :...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0541.Reverse-String-II/541. Reverse String II_test.go
leetcode/0541.Reverse-String-II/541. Reverse String II_test.go
package leetcode import ( "fmt" "testing" ) type question541 struct { para541 ans541 } // para 是参数 // one 代表第一个参数 type para541 struct { s string k int } // ans 是答案 // one 代表第一个答案 type ans541 struct { one string } func Test_Problem541(t *testing.T) { qs := []question541{ { para541{"abcdefg", 2}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0131.Palindrome-Partitioning/131. Palindrome Partitioning.go
leetcode/0131.Palindrome-Partitioning/131. Palindrome Partitioning.go
package leetcode // 解法一 func partition131(s string) [][]string { if s == "" { return [][]string{} } res, pal := [][]string{}, []string{} findPalindrome(s, 0, "", true, pal, &res) return res } func findPalindrome(str string, index int, s string, isPal bool, pal []string, res *[][]string) { if index == len(str)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0131.Palindrome-Partitioning/131. Palindrome Partitioning_test.go
leetcode/0131.Palindrome-Partitioning/131. Palindrome Partitioning_test.go
package leetcode import ( "fmt" "testing" ) type question131 struct { para131 ans131 } // para 是参数 // one 代表第一个参数 type para131 struct { s string } // ans 是答案 // one 代表第一个答案 type ans131 struct { one [][]string } func Test_Problem131(t *testing.T) { qs := []question131{ { para131{"aab"}, ans131{[][]...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1310.XOR-Queries-of-a-Subarray/1310. XOR Queries of a Subarray_test.go
leetcode/1310.XOR-Queries-of-a-Subarray/1310. XOR Queries of a Subarray_test.go
package leetcode import ( "fmt" "testing" ) type question1310 struct { para1310 ans1310 } // para 是参数 // one 代表第一个参数 type para1310 struct { arr []int queries [][]int } // ans 是答案 // one 代表第一个答案 type ans1310 struct { one []int } func Test_Problem1310(t *testing.T) { qs := []question1310{ { para13...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1310.XOR-Queries-of-a-Subarray/1310. XOR Queries of a Subarray.go
leetcode/1310.XOR-Queries-of-a-Subarray/1310. XOR Queries of a Subarray.go
package leetcode func xorQueries(arr []int, queries [][]int) []int { xors := make([]int, len(arr)) xors[0] = arr[0] for i := 1; i < len(arr); i++ { xors[i] = arr[i] ^ xors[i-1] } res := make([]int, len(queries)) for i, q := range queries { res[i] = xors[q[1]] if q[0] > 0 { res[i] ^= xors[q[0]-1] } } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0581.Shortest-Unsorted-Continuous-Subarray/581. Shortest Unsorted Continuous Subarray.go
leetcode/0581.Shortest-Unsorted-Continuous-Subarray/581. Shortest Unsorted Continuous Subarray.go
package leetcode import "math" func findUnsortedSubarray(nums []int) int { n, left, right, minR, maxL, isSort := len(nums), -1, -1, math.MaxInt32, math.MinInt32, false // left for i := 1; i < n; i++ { if nums[i] < nums[i-1] { isSort = true } if isSort { minR = min(minR, nums[i]) } } isSort = false ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0581.Shortest-Unsorted-Continuous-Subarray/581. Shortest Unsorted Continuous Subarray_test.go
leetcode/0581.Shortest-Unsorted-Continuous-Subarray/581. Shortest Unsorted Continuous Subarray_test.go
package leetcode import ( "fmt" "testing" ) type question581 struct { para581 ans581 } // para 是参数 // one 代表第一个参数 type para581 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans581 struct { one int } func Test_Problem581(t *testing.T) { qs := []question581{ { para581{[]int{2, 6, 4, 8, 10, 9, 15...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0395.Longest-Substring-with-At-Least-K-Repeating-Characters/395. Longest Substring with At Least K Repeating Characters.go
leetcode/0395.Longest-Substring-with-At-Least-K-Repeating-Characters/395. Longest Substring with At Least K Repeating Characters.go
package leetcode import "strings" // 解法一 滑动窗口 func longestSubstring(s string, k int) int { res := 0 for t := 1; t <= 26; t++ { freq, total, lessK, left, right := [26]int{}, 0, 0, 0, -1 for left < len(s) { if right+1 < len(s) && total <= t { if freq[s[right+1]-'a'] == 0 { total++ lessK++ } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0395.Longest-Substring-with-At-Least-K-Repeating-Characters/395. Longest Substring with At Least K Repeating Characters_test.go
leetcode/0395.Longest-Substring-with-At-Least-K-Repeating-Characters/395. Longest Substring with At Least K Repeating Characters_test.go
package leetcode import ( "fmt" "testing" ) type question395 struct { para395 ans395 } // para 是参数 // one 代表第一个参数 type para395 struct { s string k int } // ans 是答案 // one 代表第一个答案 type ans395 struct { one int } func Test_Problem395(t *testing.T) { qs := []question395{ { para395{"aaabb", 3}, ans395...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0611.Valid-Triangle-Number/611. Valid Triangle Number_test.go
leetcode/0611.Valid-Triangle-Number/611. Valid Triangle Number_test.go
package leetcode import ( "fmt" "testing" ) type question611 struct { para611 ans611 } // para 是参数 // one 代表第一个参数 type para611 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans611 struct { one int } func Test_Problem611(t *testing.T) { qs := []question611{ { para611{[]int{2, 2, 3, 4}}, ans6...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0611.Valid-Triangle-Number/611. Valid Triangle Number.go
leetcode/0611.Valid-Triangle-Number/611. Valid Triangle Number.go
package leetcode import "sort" func triangleNumber(nums []int) int { res := 0 sort.Ints(nums) for i := 0; i < len(nums)-2; i++ { k := i + 2 for j := i + 1; j < len(nums)-1 && nums[i] != 0; j++ { for k < len(nums) && nums[i]+nums[j] > nums[k] { k++ } res += k - j - 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/0682.Baseball-Game/682. Baseball Game.go
leetcode/0682.Baseball-Game/682. Baseball Game.go
package leetcode import "strconv" func calPoints(ops []string) int { stack := make([]int, len(ops)) top := 0 for i := 0; i < len(ops); i++ { op := ops[i] switch op { case "+": last1 := stack[top-1] last2 := stack[top-2] stack[top] = last1 + last2 top++ case "D": last1 := stack[top-1] sta...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0682.Baseball-Game/682. Baseball Game_test.go
leetcode/0682.Baseball-Game/682. Baseball Game_test.go
package leetcode import ( "fmt" "testing" ) type question682 struct { para682 ans682 } // para 是参数 // one 代表第一个参数 type para682 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans682 struct { one int } func Test_Problem682(t *testing.T) { qs := []question682{ { para682{[]string{"5", "2", "C", "...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0458.Poor-Pigs/458.Poor Pigs_test.go
leetcode/0458.Poor-Pigs/458.Poor Pigs_test.go
package leetcode import ( "fmt" "testing" ) type question458 struct { para458 ans458 } // para 是参数 type para458 struct { buckets int minutesToDie int minutesToTest int } // ans 是答案 type ans458 struct { ans int } func Test_Problem458(t *testing.T) { qs := []question458{ { para458{1000, 15, 60...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0458.Poor-Pigs/458.Poor Pigs.go
leetcode/0458.Poor-Pigs/458.Poor Pigs.go
package leetcode import "math" func poorPigs(buckets int, minutesToDie int, minutesToTest int) int { base := minutesToTest/minutesToDie + 1 return int(math.Ceil(math.Log10(float64(buckets)) / math.Log10(float64(base)))) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0448.Find-All-Numbers-Disappeared-in-an-Array/448. Find All Numbers Disappeared in an Array.go
leetcode/0448.Find-All-Numbers-Disappeared-in-an-Array/448. Find All Numbers Disappeared in an Array.go
package leetcode func findDisappearedNumbers(nums []int) []int { res := []int{} for _, v := range nums { if v < 0 { v = -v } if nums[v-1] > 0 { nums[v-1] = -nums[v-1] } } for i, v := range nums { if v > 0 { res = append(res, i+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/0448.Find-All-Numbers-Disappeared-in-an-Array/448. Find All Numbers Disappeared in an Array_test.go
leetcode/0448.Find-All-Numbers-Disappeared-in-an-Array/448. Find All Numbers Disappeared in an Array_test.go
package leetcode import ( "fmt" "testing" ) type question448 struct { para448 ans448 } // para 是参数 // one 代表第一个参数 type para448 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans448 struct { one []int } func Test_Problem448(t *testing.T) { qs := []question448{ { para448{[]int{4, 3, 2, 7, 8, 2, 3,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2182.Construct-String-With-Repeat-Limit/2182. Construct String With Repeat Limit.go
leetcode/2182.Construct-String-With-Repeat-Limit/2182. Construct String With Repeat Limit.go
package leetcode func repeatLimitedString(s string, repeatLimit int) string { cnt := make([]int, 26) for _, c := range s { cnt[int(c-'a')]++ } var ns []byte for i := 25; i >= 0; { k := i - 1 for cnt[i] > 0 { for j := 0; j < min(cnt[i], repeatLimit); j++ { ns = append(ns, byte(i)+'a') } cnt[i] -...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2182.Construct-String-With-Repeat-Limit/2182. Construct String With Repeat Limit_test.go
leetcode/2182.Construct-String-With-Repeat-Limit/2182. Construct String With Repeat Limit_test.go
package leetcode import ( "fmt" "testing" ) type question2182 struct { para2182 ans2182 } // para 是参数 // one 代表第一个参数 type para2182 struct { one string limit int } // ans 是答案 // one 代表第一个答案 type ans2182 struct { one string } func Test_Problem2182(t *testing.T) { qs := []question2182{ { para2182{"cc...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0092.Reverse-Linked-List-II/92. Reverse Linked List II.go
leetcode/0092.Reverse-Linked-List-II/92. Reverse Linked List II.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 reverseBetween(head *ListNode, m int, n int) *ListNode { if head ==...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0092.Reverse-Linked-List-II/92. Reverse Linked List II_test.go
leetcode/0092.Reverse-Linked-List-II/92. Reverse Linked List II_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question92 struct { para92 ans92 } // para 是参数 // one 代表第一个参数 type para92 struct { one []int m, n int } // ans 是答案 // one 代表第一个答案 type ans92 struct { one []int } func Test_Problem92(t *testing.T) { qs := []que...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0041.First-Missing-Positive/41. First Missing Positive_test.go
leetcode/0041.First-Missing-Positive/41. First Missing Positive_test.go
package leetcode import ( "fmt" "testing" ) type question41 struct { para41 ans41 } // para 是参数 // one 代表第一个参数 type para41 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans41 struct { one int } func Test_Problem41(t *testing.T) { qs := []question41{ { para41{[]int{10, -1, 1, 2, 2, 3, 3, 3, 4, 4...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0041.First-Missing-Positive/41. First Missing Positive.go
leetcode/0041.First-Missing-Positive/41. First Missing Positive.go
package leetcode func firstMissingPositive(nums []int) int { numMap := make(map[int]int, len(nums)) for _, v := range nums { numMap[v] = v } for index := 1; index < len(nums)+1; index++ { if _, ok := numMap[index]; !ok { return index } } return len(nums) + 1 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0648.Replace-Words/648. Replace Words_test.go
leetcode/0648.Replace-Words/648. Replace Words_test.go
package leetcode import ( "fmt" "testing" ) type question648 struct { para648 ans648 } // para 是参数 // one 代表第一个参数 type para648 struct { one []string s string } // ans 是答案 // one 代表第一个答案 type ans648 struct { one string } func Test_Problem648(t *testing.T) { qs := []question648{ { para648{[]string{"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0648.Replace-Words/648. Replace Words.go
leetcode/0648.Replace-Words/648. Replace Words.go
package leetcode import "strings" // 解法一 哈希表 func replaceWords(dict []string, sentence string) string { roots := make(map[byte][]string) for _, root := range dict { b := root[0] roots[b] = append(roots[b], root) } words := strings.Split(sentence, " ") for i, word := range words { b := []byte(word) for j ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0876.Middle-of-the-Linked-List/876. Middle of the Linked List_test.go
leetcode/0876.Middle-of-the-Linked-List/876. Middle of the Linked List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question876 struct { para876 ans876 } // para 是参数 // one 代表第一个参数 type para876 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans876 struct { one int } func Test_Problem876(t *testing.T) { qs := []question87...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0876.Middle-of-the-Linked-List/876. Middle of the Linked List.go
leetcode/0876.Middle-of-the-Linked-List/876. Middle of the Linked List.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 middleNode(head *ListNode) *ListNode { if head == nil || head.Next ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0046.Permutations/46. Permutations_test.go
leetcode/0046.Permutations/46. Permutations_test.go
package leetcode import ( "fmt" "testing" ) type question46 struct { para46 ans46 } // para 是参数 // one 代表第一个参数 type para46 struct { s []int } // ans 是答案 // one 代表第一个答案 type ans46 struct { one [][]int } func Test_Problem46(t *testing.T) { qs := []question46{ { para46{[]int{1, 2, 3}}, ans46{[][]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0046.Permutations/46. Permutations.go
leetcode/0046.Permutations/46. Permutations.go
package leetcode func permute(nums []int) [][]int { if len(nums) == 0 { return [][]int{} } used, p, res := make([]bool, len(nums)), []int{}, [][]int{} generatePermutation(nums, 0, p, &res, &used) return res } func generatePermutation(nums []int, index int, p []int, res *[][]int, used *[]bool) { if index == le...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1232.Check-If-It-Is-a-Straight-Line/1232. Check If It Is a Straight Line.go
leetcode/1232.Check-If-It-Is-a-Straight-Line/1232. Check If It Is a Straight Line.go
package leetcode func checkStraightLine(coordinates [][]int) bool { dx0 := coordinates[1][0] - coordinates[0][0] dy0 := coordinates[1][1] - coordinates[0][1] for i := 1; i < len(coordinates)-1; i++ { dx := coordinates[i+1][0] - coordinates[i][0] dy := coordinates[i+1][1] - coordinates[i][1] if dy*dx0 != dy0*d...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1232.Check-If-It-Is-a-Straight-Line/1232. Check If It Is a Straight Line_test.go
leetcode/1232.Check-If-It-Is-a-Straight-Line/1232. Check If It Is a Straight Line_test.go
package leetcode import ( "fmt" "testing" ) type question1232 struct { para1232 ans1232 } // para 是参数 // one 代表第一个参数 type para1232 struct { arr [][]int } // ans 是答案 // one 代表第一个答案 type ans1232 struct { one bool } func Test_Problem1232(t *testing.T) { qs := []question1232{ { para1232{[][]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/0315.Count-of-Smaller-Numbers-After-Self/315. Count of Smaller Numbers After Self.go
leetcode/0315.Count-of-Smaller-Numbers-After-Self/315. Count of Smaller Numbers After Self.go
package leetcode import ( "sort" "github.com/halfrost/LeetCode-Go/template" ) // 解法一 线段树 func countSmaller(nums []int) []int { if len(nums) == 0 { return []int{} } st, minNum, numsMap, numsArray, res := template.SegmentCountTree{}, 0, make(map[int]int, 0), []int{}, make([]int, len(nums)) for i := 0; i < len(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0315.Count-of-Smaller-Numbers-After-Self/315. Count of Smaller Numbers After Self_test.go
leetcode/0315.Count-of-Smaller-Numbers-After-Self/315. Count of Smaller Numbers After Self_test.go
package leetcode import ( "fmt" "testing" ) type question315 struct { para315 ans315 } // para 是参数 // one 代表第一个参数 type para315 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans315 struct { one []int } func Test_Problem315(t *testing.T) { qs := []question315{ { para315{[]int{5, 2, 6, 1}}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0417.Pacific-Atlantic-Water-Flow/417. Pacific Atlantic Water Flow.go
leetcode/0417.Pacific-Atlantic-Water-Flow/417. Pacific Atlantic Water Flow.go
package leetcode import "math" func pacificAtlantic(matrix [][]int) [][]int { if len(matrix) == 0 || len(matrix[0]) == 0 { return nil } row, col, res := len(matrix), len(matrix[0]), make([][]int, 0) pacific, atlantic := make([][]bool, row), make([][]bool, row) for i := 0; i < row; i++ { pacific[i] = make([]b...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0417.Pacific-Atlantic-Water-Flow/417. Pacific Atlantic Water Flow_test.go
leetcode/0417.Pacific-Atlantic-Water-Flow/417. Pacific Atlantic Water Flow_test.go
package leetcode import ( "fmt" "testing" ) type question417 struct { para417 ans417 } // para 是参数 // one 代表第一个参数 type para417 struct { matrix [][]int } // ans 是答案 // one 代表第一个答案 type ans417 struct { one [][]int } func Test_Problem417(t *testing.T) { qs := []question417{ { para417{[][]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/0930.Binary-Subarrays-With-Sum/930. Binary Subarrays With Sum_test.go
leetcode/0930.Binary-Subarrays-With-Sum/930. Binary Subarrays With Sum_test.go
package leetcode import ( "fmt" "testing" ) type question930 struct { para930 ans930 } // para 是参数 // one 代表第一个参数 type para930 struct { s []int k int } // ans 是答案 // one 代表第一个答案 type ans930 struct { one int } func Test_Problem930(t *testing.T) { qs := []question930{ { para930{[]int{1, 0, 1, 0, 1}, 2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0930.Binary-Subarrays-With-Sum/930. Binary Subarrays With Sum.go
leetcode/0930.Binary-Subarrays-With-Sum/930. Binary Subarrays With Sum.go
package leetcode import "fmt" func numSubarraysWithSum(A []int, S int) int { freq, sum, res := make([]int, len(A)+1), 0, 0 freq[0] = 1 for _, v := range A { t := sum + v - S if t >= 0 { // 总和有多余的,需要减去 t,除去的方法有 freq[t] 种 res += freq[t] } sum += v freq[sum]++ fmt.Printf("freq = %v sum = %v res = %v...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1442.Count-Triplets-That-Can-Form-Two-Arrays-of-Equal-XOR/1442. Count Triplets That Can Form Two Arrays of Equal XOR.go
leetcode/1442.Count-Triplets-That-Can-Form-Two-Arrays-of-Equal-XOR/1442. Count Triplets That Can Form Two Arrays of Equal XOR.go
package leetcode func countTriplets(arr []int) int { prefix, num, count, total := make([]int, len(arr)), 0, 0, 0 for i, v := range arr { num ^= v prefix[i] = num } for i := 0; i < len(prefix)-1; i++ { for k := i + 1; k < len(prefix); k++ { total = prefix[k] if i > 0 { total ^= prefix[i-1] } i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1442.Count-Triplets-That-Can-Form-Two-Arrays-of-Equal-XOR/1442. Count Triplets That Can Form Two Arrays of Equal XOR_test.go
leetcode/1442.Count-Triplets-That-Can-Form-Two-Arrays-of-Equal-XOR/1442. Count Triplets That Can Form Two Arrays of Equal XOR_test.go
package leetcode import ( "fmt" "testing" ) type question1442 struct { para1442 ans1442 } // para 是参数 // one 代表第一个参数 type para1442 struct { arr []int } // ans 是答案 // one 代表第一个答案 type ans1442 struct { one int } func Test_Problem1442(t *testing.T) { qs := []question1442{ { para1442{[]int{2, 3, 1, 6, 7}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0112.Path-Sum/112. Path Sum_test.go
leetcode/0112.Path-Sum/112. Path Sum_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question112 struct { para112 ans112 } // para 是参数 // one 代表第一个参数 type para112 struct { one []int sum int } // ans 是答案 // one 代表第一个答案 type ans112 struct { one bool } func Test_Problem112(t *testing.T) { qs := []...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0112.Path-Sum/112. Path Sum.go
leetcode/0112.Path-Sum/112. Path Sum.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 hasPathSum(root *TreeNode, sum int) bool { i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee/714. Best Time to Buy and Sell Stock with Transaction Fee_test.go
leetcode/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee/714. Best Time to Buy and Sell Stock with Transaction Fee_test.go
package leetcode import ( "fmt" "testing" ) type question714 struct { para714 ans714 } // para 是参数 // one 代表第一个参数 type para714 struct { one []int f int } // ans 是答案 // one 代表第一个答案 type ans714 struct { one int } func Test_Problem714(t *testing.T) { qs := []question714{ { para714{[]int{}, 0}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee/714. Best Time to Buy and Sell Stock with Transaction Fee.go
leetcode/0714.Best-Time-to-Buy-and-Sell-Stock-with-Transaction-Fee/714. Best Time to Buy and Sell Stock with Transaction Fee.go
package leetcode import ( "math" ) // 解法一 模拟 DP func maxProfit714(prices []int, fee int) int { if len(prices) <= 1 { return 0 } buy, sell := make([]int, len(prices)), make([]int, len(prices)) for i := range buy { buy[i] = math.MinInt64 } buy[0] = -prices[0] for i := 1; i < len(prices); i++ { buy[i] = ma...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0463.Island-Perimeter/463. Island Perimeter_test.go
leetcode/0463.Island-Perimeter/463. Island Perimeter_test.go
package leetcode import ( "fmt" "testing" ) type question463 struct { para463 ans463 } // para 是参数 // one 代表第一个参数 type para463 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans463 struct { one int } func Test_Problem463(t *testing.T) { qs := []question463{ { para463{[][]int{{0, 1, 0, 0}, {1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0463.Island-Perimeter/463. Island Perimeter.go
leetcode/0463.Island-Perimeter/463. Island Perimeter.go
package leetcode func islandPerimeter(grid [][]int) int { counter := 0 for i := 0; i < len(grid); i++ { for j := 0; j < len(grid[0]); j++ { if grid[i][j] == 1 { if i-1 < 0 || grid[i-1][j] == 0 { counter++ } if i+1 >= len(grid) || grid[i+1][j] == 0 { counter++ } if j-1 < 0 || grid[i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0747.Largest-Number-At-Least-Twice-of-Others/747. Largest Number At Least Twice of Others_test.go
leetcode/0747.Largest-Number-At-Least-Twice-of-Others/747. Largest Number At Least Twice of Others_test.go
package leetcode import ( "fmt" "testing" ) type question747 struct { para747 ans747 } // para 是参数 // one 代表第一个参数 type para747 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans747 struct { one int } func Test_Problem747(t *testing.T) { qs := []question747{ { para747{[]int{3, 6, 1, 0}}, ans7...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0747.Largest-Number-At-Least-Twice-of-Others/747. Largest Number At Least Twice of Others.go
leetcode/0747.Largest-Number-At-Least-Twice-of-Others/747. Largest Number At Least Twice of Others.go
package leetcode func dominantIndex(nums []int) int { maxNum, flag, index := 0, false, 0 for i, v := range nums { if v > maxNum { maxNum = v index = i } } for _, v := range nums { if v != maxNum && 2*v > maxNum { flag = true } } if flag { return -1 } return index }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0973.K-Closest-Points-to-Origin/973. K Closest Points to Origin_test.go
leetcode/0973.K-Closest-Points-to-Origin/973. K Closest Points to Origin_test.go
package leetcode import ( "fmt" "testing" ) type question973 struct { para973 ans973 } // para 是参数 // one 代表第一个参数 type para973 struct { one [][]int two int } // ans 是答案 // one 代表第一个答案 type ans973 struct { one [][]int } func Test_Problem973(t *testing.T) { qs := []question973{ { para973{[][]int{{1, 3...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0973.K-Closest-Points-to-Origin/973. K Closest Points to Origin.go
leetcode/0973.K-Closest-Points-to-Origin/973. K Closest Points to Origin.go
package leetcode import "sort" // KClosest define func KClosest(points [][]int, K int) [][]int { sort.Slice(points, func(i, j int) bool { return points[i][0]*points[i][0]+points[i][1]*points[i][1] < points[j][0]*points[j][0]+points[j][1]*points[j][1] }) ans := make([][]int, K) for i := 0; i < K; i++ { ans[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0146.LRU-Cache/146. LRU Cache.go
leetcode/0146.LRU-Cache/146. LRU Cache.go
package leetcode type LRUCache struct { head, tail *Node Keys map[int]*Node Cap int } type Node struct { Key, Val int Prev, Next *Node } func Constructor(capacity int) LRUCache { return LRUCache{Keys: make(map[int]*Node), Cap: capacity} } func (this *LRUCache) Get(key int) int { if node, ok :=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0146.LRU-Cache/146. LRU Cache_test.go
leetcode/0146.LRU-Cache/146. LRU Cache_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem146(t *testing.T) { obj := Constructor(2) fmt.Printf("obj = %v\n", MList2Ints(&obj)) obj.Put(1, 1) fmt.Printf("obj = %v\n", MList2Ints(&obj)) obj.Put(2, 2) fmt.Printf("obj = %v\n", MList2Ints(&obj)) param1 := obj.Get(1) fmt.Printf("param_1 = %v ob...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1011.Capacity-To-Ship-Packages-Within-D-Days/1011. Capacity To Ship Packages Within D Days.go
leetcode/1011.Capacity-To-Ship-Packages-Within-D-Days/1011. Capacity To Ship Packages Within D Days.go
package leetcode func shipWithinDays(weights []int, D int) int { maxNum, sum := 0, 0 for _, num := range weights { sum += num if num > maxNum { maxNum = num } } if D == 1 { return sum } low, high := maxNum, sum for low < high { mid := low + (high-low)>>1 if calSum(mid, D, weights) { high = mid...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1011.Capacity-To-Ship-Packages-Within-D-Days/1011. Capacity To Ship Packages Within D Days_test.go
leetcode/1011.Capacity-To-Ship-Packages-Within-D-Days/1011. Capacity To Ship Packages Within D Days_test.go
package leetcode import ( "fmt" "testing" ) type question1011 struct { para1011 ans1011 } // para 是参数 // one 代表第一个参数 type para1011 struct { weights []int D int } // ans 是答案 // one 代表第一个答案 type ans1011 struct { one int } func Test_Problem1011(t *testing.T) { qs := []question1011{ { para1011{[]i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0052.N-Queens-II/52. N-Queens II.go
leetcode/0052.N-Queens-II/52. N-Queens II.go
package leetcode // 解法一,暴力打表法 func totalNQueens(n int) int { res := []int{0, 1, 0, 0, 2, 10, 4, 40, 92, 352, 724} return res[n] } // 解法二,DFS 回溯法 func totalNQueens1(n int) int { col, dia1, dia2, row, res := make([]bool, n), make([]bool, 2*n-1), make([]bool, 2*n-1), []int{}, 0 putQueen52(n, 0, &col, &dia1, &dia2, &...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0052.N-Queens-II/52. N-Queens II_test.go
leetcode/0052.N-Queens-II/52. N-Queens II_test.go
package leetcode import ( "fmt" "testing" ) type question52 struct { para52 ans52 } // para 是参数 // one 代表第一个参数 type para52 struct { one int } // ans 是答案 // one 代表第一个答案 type ans52 struct { one int } func Test_Problem52(t *testing.T) { qs := []question52{ { para52{1}, ans52{1}, }, { para52{2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0076.Minimum-Window-Substring/76. Minimum Window Substring_test.go
leetcode/0076.Minimum-Window-Substring/76. Minimum Window Substring_test.go
package leetcode import ( "fmt" "testing" ) type question76 struct { para76 ans76 } // para 是参数 // one 代表第一个参数 type para76 struct { s string p string } // ans 是答案 // one 代表第一个答案 type ans76 struct { one string } func Test_Problem76(t *testing.T) { qs := []question76{ { para76{"ADOBECODEBANC", "ABC"},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0076.Minimum-Window-Substring/76. Minimum Window Substring.go
leetcode/0076.Minimum-Window-Substring/76. Minimum Window Substring.go
package leetcode func minWindow(s string, t string) string { if s == "" || t == "" { return "" } var tFreq, sFreq [256]int result, left, right, finalLeft, finalRight, minW, count := "", 0, -1, -1, -1, len(s)+1, 0 for i := 0; i < len(t); i++ { tFreq[t[i]-'a']++ } for left < len(s) { if right+1 < len(s) &...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0424.Longest-Repeating-Character-Replacement/424. Longest Repeating Character Replacement.go
leetcode/0424.Longest-Repeating-Character-Replacement/424. Longest Repeating Character Replacement.go
package leetcode func characterReplacement(s string, k int) int { res, left, counter, freq := 0, 0, 0, make([]int, 26) for right := 0; right < len(s); right++ { freq[s[right]-'A']++ counter = max(counter, freq[s[right]-'A']) for right-left+1-counter > k { freq[s[left]-'A']-- left++ } res = max(res, r...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0424.Longest-Repeating-Character-Replacement/424. Longest Repeating Character Replacement_test.go
leetcode/0424.Longest-Repeating-Character-Replacement/424. Longest Repeating Character Replacement_test.go
package leetcode import ( "fmt" "testing" ) type question424 struct { para424 ans424 } // para 是参数 // one 代表第一个参数 type para424 struct { s string k int } // ans 是答案 // one 代表第一个答案 type ans424 struct { one int } func Test_Problem424(t *testing.T) { qs := []question424{ { para424{"AABABBA", 1}, ans4...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0349.Intersection-of-Two-Arrays/349. Intersection of Two Arrays.go
leetcode/0349.Intersection-of-Two-Arrays/349. Intersection of Two Arrays.go
package leetcode func intersection(nums1 []int, nums2 []int) []int { m := map[int]bool{} var res []int for _, n := range nums1 { m[n] = true } for _, n := range nums2 { if m[n] { delete(m, n) res = append(res, n) } } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0349.Intersection-of-Two-Arrays/349. Intersection of Two Arrays_test.go
leetcode/0349.Intersection-of-Two-Arrays/349. Intersection of Two Arrays_test.go
package leetcode import ( "fmt" "testing" ) type question349 struct { para349 ans349 } // para 是参数 // one 代表第一个参数 type para349 struct { one []int another []int } // ans 是答案 // one 代表第一个答案 type ans349 struct { one []int } func Test_Problem349(t *testing.T) { qs := []question349{ { para349{[]int{}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0599.Minimum-Index-Sum-of-Two-Lists/599. Minimum Index Sum of Two Lists_test.go
leetcode/0599.Minimum-Index-Sum-of-Two-Lists/599. Minimum Index Sum of Two Lists_test.go
package leetcode import ( "fmt" "testing" ) type question599 struct { para599 ans599 } // para 是参数 // one 代表第一个参数 type para599 struct { one []string two []string } // ans 是答案 // one 代表第一个答案 type ans599 struct { one []string } func Test_Problem599(t *testing.T) { qs := []question599{ { para599{[]stri...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0599.Minimum-Index-Sum-of-Two-Lists/599. Minimum Index Sum of Two Lists.go
leetcode/0599.Minimum-Index-Sum-of-Two-Lists/599. Minimum Index Sum of Two Lists.go
package leetcode func findRestaurant(list1 []string, list2 []string) []string { m, ans := make(map[string]int, len(list1)), []string{} for i, r := range list1 { m[r] = i } for j, r := range list2 { if _, ok := m[r]; ok { m[r] += j if len(ans) == 0 || m[r] == m[ans[0]] { ans = append(ans, r) } else...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false