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/0500.Keyboard-Row/500. Keyboard Row.go
leetcode/0500.Keyboard-Row/500. Keyboard Row.go
package leetcode import "strings" func findWords500(words []string) []string { rows := []string{"qwertyuiop", "asdfghjkl", "zxcvbnm"} output := make([]string, 0) for _, s := range words { if len(s) == 0 { continue } lowerS := strings.ToLower(s) oneRow := false for _, r := range rows { if strings.Co...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0500.Keyboard-Row/500. Keyboard Row_test.go
leetcode/0500.Keyboard-Row/500. Keyboard Row_test.go
package leetcode import ( "fmt" "testing" ) type question500 struct { para500 ans500 } // para 是参数 // one 代表第一个参数 type para500 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans500 struct { one []string } func Test_Problem500(t *testing.T) { qs := []question500{ { para500{[]string{"Hello", "A...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0199.Binary-Tree-Right-Side-View/199. Binary Tree Right Side View_test.go
leetcode/0199.Binary-Tree-Right-Side-View/199. Binary Tree Right Side View_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question199 struct { para199 ans199 } // para 是参数 // one 代表第一个参数 type para199 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans199 struct { one []int } func Test_Problem199(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/0199.Binary-Tree-Right-Side-View/199. Binary Tree Right Side View.go
leetcode/0199.Binary-Tree-Right-Side-View/199. Binary Tree Right Side View.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 rightSideView(root *TreeNode) []int { res :=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0226.Invert-Binary-Tree/226. Invert Binary Tree.go
leetcode/0226.Invert-Binary-Tree/226. Invert 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 invertTree(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/0226.Invert-Binary-Tree/226. Invert Binary Tree_test.go
leetcode/0226.Invert-Binary-Tree/226. Invert Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question226 struct { para226 ans226 } // para 是参数 // one 代表第一个参数 type para226 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans226 struct { one []int } func Test_Problem226(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/0583.Delete-Operation-for-Two-Strings/583. Delete Operation for Two Strings.go
leetcode/0583.Delete-Operation-for-Two-Strings/583. Delete Operation for Two Strings.go
package leetcode func minDistance(word1 string, word2 string) int { dp := make([][]int, len(word1)+1) for i := 0; i < len(word1)+1; i++ { dp[i] = make([]int, len(word2)+1) } for i := 0; i < len(word1)+1; i++ { dp[i][0] = i } for i := 0; i < len(word2)+1; i++ { dp[0][i] = i } for i := 1; i < len(word1)+1;...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0583.Delete-Operation-for-Two-Strings/583. Delete Operation for Two Strings_test.go
leetcode/0583.Delete-Operation-for-Two-Strings/583. Delete Operation for Two Strings_test.go
package leetcode import ( "fmt" "testing" ) type question583 struct { para583 ans583 } // para 是参数 // one 代表第一个参数 type para583 struct { word1 string word2 string } // ans 是答案 // one 代表第一个答案 type ans583 struct { one int } func Test_Problem583(t *testing.T) { qs := []question583{ { para583{"sea", "eat...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0870.Advantage-Shuffle/870. Advantage Shuffle.go
leetcode/0870.Advantage-Shuffle/870. Advantage Shuffle.go
package leetcode import "sort" func advantageCount1(A []int, B []int) []int { n := len(A) sort.Ints(A) sortedB := make([]int, n) for i := range sortedB { sortedB[i] = i } sort.Slice(sortedB, func(i, j int) bool { return B[sortedB[i]] < B[sortedB[j]] }) useless, i, res := make([]int, 0), 0, make([]int, n) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0870.Advantage-Shuffle/870. Advantage Shuffle_test.go
leetcode/0870.Advantage-Shuffle/870. Advantage Shuffle_test.go
package leetcode import ( "fmt" "testing" ) type question870 struct { para870 ans870 } // para 是参数 // one 代表第一个参数 type para870 struct { A []int B []int } // ans 是答案 // one 代表第一个答案 type ans870 struct { one []int } func Test_Problem870(t *testing.T) { qs := []question870{ { para870{[]int{2, 7, 11, 15}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1720.Decode-XORed-Array/1720. Decode XORed Array_test.go
leetcode/1720.Decode-XORed-Array/1720. Decode XORed Array_test.go
package leetcode import ( "fmt" "testing" ) type question1720 struct { para1720 ans1720 } // para 是参数 // one 代表第一个参数 type para1720 struct { encoded []int first int } // ans 是答案 // one 代表第一个答案 type ans1720 struct { one []int } func Test_Problem1720(t *testing.T) { qs := []question1720{ { para1720{[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1720.Decode-XORed-Array/1720. Decode XORed Array.go
leetcode/1720.Decode-XORed-Array/1720. Decode XORed Array.go
package leetcode func decode(encoded []int, first int) []int { arr := make([]int, len(encoded)+1) arr[0] = first for i, val := range encoded { arr[i+1] = arr[i] ^ val } return arr }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0632.Smallest-Range-Covering-Elements-from-K-Lists/632. Smallest Range Covering Elements from K Lists_test.go
leetcode/0632.Smallest-Range-Covering-Elements-from-K-Lists/632. Smallest Range Covering Elements from K Lists_test.go
package leetcode import ( "fmt" "testing" ) type question632 struct { para632 ans632 } // para 是参数 // one 代表第一个参数 type para632 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans632 struct { one []int } func Test_Problem632(t *testing.T) { qs := []question632{ { para632{[][]int{{4, 10, 15, 24, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0632.Smallest-Range-Covering-Elements-from-K-Lists/632. Smallest Range Covering Elements from K Lists.go
leetcode/0632.Smallest-Range-Covering-Elements-from-K-Lists/632. Smallest Range Covering Elements from K Lists.go
package leetcode import ( "math" "sort" ) func smallestRange(nums [][]int) []int { numList, left, right, count, freqMap, res, length := []element{}, 0, -1, 0, map[int]int{}, make([]int, 2), math.MaxInt64 for i, ns := range nums { for _, v := range ns { numList = append(numList, element{val: v, index: i}) }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0842.Split-Array-into-Fibonacci-Sequence/842. Split Array into Fibonacci Sequence.go
leetcode/0842.Split-Array-into-Fibonacci-Sequence/842. Split Array into Fibonacci Sequence.go
package leetcode import ( "strconv" "strings" ) func splitIntoFibonacci(S string) []int { if len(S) < 3 { return []int{} } res, isComplete := []int{}, false for firstEnd := 0; firstEnd < len(S)/2; firstEnd++ { if S[0] == '0' && firstEnd > 0 { break } first, _ := strconv.Atoi(S[:firstEnd+1]) if firs...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0842.Split-Array-into-Fibonacci-Sequence/842. Split Array into Fibonacci Sequence_test.go
leetcode/0842.Split-Array-into-Fibonacci-Sequence/842. Split Array into Fibonacci Sequence_test.go
package leetcode import ( "fmt" "testing" ) type question842 struct { para842 ans842 } // para 是参数 // one 代表第一个参数 type para842 struct { one string } // ans 是答案 // one 代表第一个答案 type ans842 struct { one []int } func Test_Problem842(t *testing.T) { qs := []question842{ { para842{"11235813"}, ans842{[]...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0718.Maximum-Length-of-Repeated-Subarray/718. Maximum Length of Repeated Subarray_test.go
leetcode/0718.Maximum-Length-of-Repeated-Subarray/718. Maximum Length of Repeated Subarray_test.go
package leetcode import ( "fmt" "testing" ) type question718 struct { para718 ans718 } // para 是参数 // one 代表第一个参数 type para718 struct { A []int B []int } // ans 是答案 // one 代表第一个答案 type ans718 struct { one int } func Test_Problem718(t *testing.T) { qs := []question718{ { para718{[]int{0, 0, 0, 0, 0},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0718.Maximum-Length-of-Repeated-Subarray/718. Maximum Length of Repeated Subarray.go
leetcode/0718.Maximum-Length-of-Repeated-Subarray/718. Maximum Length of Repeated Subarray.go
package leetcode const primeRK = 16777619 // 解法一 二分搜索 + Rabin-Karp func findLength(A []int, B []int) int { low, high := 0, min(len(A), len(B)) for low < high { mid := (low + high + 1) >> 1 if hasRepeated(A, B, mid) { low = mid } else { high = mid - 1 } } return low } func min(a int, b int) int { i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1110.Delete-Nodes-And-Return-Forest/1110. Delete Nodes And Return Forest_test.go
leetcode/1110.Delete-Nodes-And-Return-Forest/1110. Delete Nodes And Return Forest_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1110 struct { para1110 ans1110 } // para 是参数 // one 代表第一个参数 type para1110 struct { one []int two []int } // ans 是答案 // one 代表第一个答案 type ans1110 struct { one [][]int } func Test_Problem1110(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/1110.Delete-Nodes-And-Return-Forest/1110. Delete Nodes And Return Forest.go
leetcode/1110.Delete-Nodes-And-Return-Forest/1110. Delete Nodes And Return Forest.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 delNodes(root *TreeNode, toDelete []int) []*Tr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0028.Find-the-Index-of-the-First-Occurrence-in-a-String/28. Find the Index of the First Occurrence in a String_test.go
leetcode/0028.Find-the-Index-of-the-First-Occurrence-in-a-String/28. Find the Index of the First Occurrence in a String_test.go
package leetcode import ( "fmt" "testing" ) type question28 struct { para28 ans28 } // para 是参数 // one 代表第一个参数 type para28 struct { s string p string } // ans 是答案 // one 代表第一个答案 type ans28 struct { one int } func Test_Problem28(t *testing.T) { qs := []question28{ { para28{"abab", "ab"}, ans28{0},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0028.Find-the-Index-of-the-First-Occurrence-in-a-String/28. Find the Index of the First Occurrence in a String.go
leetcode/0028.Find-the-Index-of-the-First-Occurrence-in-a-String/28. Find the Index of the First Occurrence in a String.go
package leetcode import "strings" // 解法一 func strStr(haystack string, needle string) int { for i := 0; ; i++ { for j := 0; ; j++ { if j == len(needle) { return i } if i+j == len(haystack) { return -1 } if needle[j] != haystack[i+j] { break } } } } // 解法二 func strStr1(haystack stri...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0078.Subsets/78. Subsets_test.go
leetcode/0078.Subsets/78. Subsets_test.go
package leetcode import ( "fmt" "testing" ) type question78 struct { para78 ans78 } // para 是参数 // one 代表第一个参数 type para78 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans78 struct { one [][]int } func Test_Problem78(t *testing.T) { qs := []question78{ { para78{[]int{}}, ans78{[][]int{{}}},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0078.Subsets/78. Subsets.go
leetcode/0078.Subsets/78. Subsets.go
package leetcode import "sort" // 解法一 func subsets(nums []int) [][]int { c, res := []int{}, [][]int{} for k := 0; k <= len(nums); k++ { generateSubsets(nums, k, 0, c, &res) } return res } func generateSubsets(nums []int, k, start int, c []int, res *[][]int) { if len(c) == k { b := make([]int, len(c)) copy...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring_test.go
leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring_test.go
package leetcode import ( "fmt" "testing" ) type question1668 struct { para1668 ans1668 } // para 是参数 // one 代表第一个参数 type para1668 struct { sequence string word string } // ans 是答案 // one 代表第一个答案 type ans1668 struct { one int } func Test_Problem1668(t *testing.T) { qs := []question1668{ { para16...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring.go
leetcode/1668.Maximum-Repeating-Substring/1668. Maximum Repeating Substring.go
package leetcode import ( "strings" ) func maxRepeating(sequence string, word string) int { for i := len(sequence) / len(word); i >= 0; i-- { tmp := "" for j := 0; j < i; j++ { tmp += word } if strings.Contains(sequence, tmp) { return i } } return 0 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0815.Bus-Routes/815. Bus Routes.go
leetcode/0815.Bus-Routes/815. Bus Routes.go
package leetcode func numBusesToDestination(routes [][]int, S int, T int) int { if S == T { return 0 } // vertexMap 中 key 是站点,value 是公交车数组,代表这些公交车路线可以到达此站点 vertexMap, visited, queue, res := map[int][]int{}, make([]bool, len(routes)), []int{}, 0 for i := 0; i < len(routes); i++ { for _, v := range routes[i] { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0815.Bus-Routes/815. Bus Routes_test.go
leetcode/0815.Bus-Routes/815. Bus Routes_test.go
package leetcode import ( "fmt" "testing" ) type question815 struct { para815 ans815 } // para 是参数 // one 代表第一个参数 type para815 struct { r [][]int s int t int } // ans 是答案 // one 代表第一个答案 type ans815 struct { one int } func Test_Problem815(t *testing.T) { qs := []question815{ { para815{[][]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/0724.Find-Pivot-Index/724. Find Pivot Index_test.go
leetcode/0724.Find-Pivot-Index/724. Find Pivot Index_test.go
package leetcode import ( "fmt" "testing" ) type question724 struct { para724 ans724 } // para 是参数 // one 代表第一个参数 type para724 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans724 struct { n int } func Test_Problem724(t *testing.T) { qs := []question724{ { para724{[]int{1, 7, 3, 6, 5, 6}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0724.Find-Pivot-Index/724. Find Pivot Index.go
leetcode/0724.Find-Pivot-Index/724. Find Pivot Index.go
package leetcode // 2 * leftSum + num[i] = sum // 时间: O(n) // 空间: O(1) func pivotIndex(nums []int) int { if len(nums) <= 0 { return -1 } var sum, leftSum int for _, num := range nums { sum += num } for index, num := range nums { if leftSum*2+num == sum { return index } leftSum += num } return -1 }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0212.Word-Search-II/212. Word Search II_test.go
leetcode/0212.Word-Search-II/212. Word Search II_test.go
package leetcode import ( "fmt" "testing" ) type question212 struct { para212 ans212 } // para 是参数 // one 代表第一个参数 type para212 struct { b [][]byte word []string } // ans 是答案 // one 代表第一个答案 type ans212 struct { one []string } func Test_Problem212(t *testing.T) { qs := []question212{ { para212{[][]...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0212.Word-Search-II/212. Word Search II.go
leetcode/0212.Word-Search-II/212. Word Search II.go
package leetcode func findWords(board [][]byte, words []string) []string { res := []string{} for _, v := range words { if exist(board, v) { res = append(res, v) } } return res } // these is 79 solution var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } func exist(board [][]byte, word string) bool ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0839.Similar-String-Groups/839. Similar String Groups_test.go
leetcode/0839.Similar-String-Groups/839. Similar String Groups_test.go
package leetcode import ( "fmt" "testing" ) type question839 struct { para839 ans839 } // para 是参数 // one 代表第一个参数 type para839 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans839 struct { one int } func Test_Problem839(t *testing.T) { qs := []question839{ { para839{[]string{"tars", "rats", ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0839.Similar-String-Groups/839. Similar String Groups.go
leetcode/0839.Similar-String-Groups/839. Similar String Groups.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) func numSimilarGroups(A []string) int { uf := template.UnionFind{} uf.Init(len(A)) for i := 0; i < len(A); i++ { for j := i + 1; j < len(A); j++ { if isSimilar(A[i], A[j]) { uf.Union(i, j) } } } return uf.TotalCount() } func i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1579.Remove-Max-Number-of-Edges-to-Keep-Graph-Fully-Traversable/1579. Remove Max Number of Edges to Keep Graph Fully Traversable.go
leetcode/1579.Remove-Max-Number-of-Edges-to-Keep-Graph-Fully-Traversable/1579. Remove Max Number of Edges to Keep Graph Fully Traversable.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) func maxNumEdgesToRemove(n int, edges [][]int) int { alice, bob, res := template.UnionFind{}, template.UnionFind{}, len(edges) alice.Init(n) bob.Init(n) for _, e := range edges { x, y := e[1]-1, e[2]-1 if e[0] == 3 && (!(alice.Find(x) == ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1579.Remove-Max-Number-of-Edges-to-Keep-Graph-Fully-Traversable/1579. Remove Max Number of Edges to Keep Graph Fully Traversable_test.go
leetcode/1579.Remove-Max-Number-of-Edges-to-Keep-Graph-Fully-Traversable/1579. Remove Max Number of Edges to Keep Graph Fully Traversable_test.go
package leetcode import ( "fmt" "testing" ) type question1579 struct { para1579 ans1579 } // para 是参数 // one 代表第一个参数 type para1579 struct { n int edges [][]int } // ans 是答案 // one 代表第一个答案 type ans1579 struct { one int } func Test_Problem1579(t *testing.T) { qs := []question1579{ { para1579{4, []...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1049.Last-Stone-Weight-II/1049. Last Stone Weight II.go
leetcode/1049.Last-Stone-Weight-II/1049. Last Stone Weight II.go
package leetcode func lastStoneWeightII(stones []int) int { sum := 0 for _, v := range stones { sum += v } n, C, dp := len(stones), sum/2, make([]int, sum/2+1) for i := 0; i <= C; i++ { if stones[0] <= i { dp[i] = stones[0] } else { dp[i] = 0 } } for i := 1; i < n; i++ { for j := C; j >= stones[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1049.Last-Stone-Weight-II/1049. Last Stone Weight II_test.go
leetcode/1049.Last-Stone-Weight-II/1049. Last Stone Weight II_test.go
package leetcode import ( "fmt" "testing" ) type question1049 struct { para1049 ans1049 } // para 是参数 // one 代表第一个参数 type para1049 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1049 struct { one int } func Test_Problem1049(t *testing.T) { qs := []question1049{ { para1049{[]int{2, 7, 4, 1, 8,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1675.Minimize-Deviation-in-Array/1675. Minimize Deviation in Array.go
leetcode/1675.Minimize-Deviation-in-Array/1675. Minimize Deviation in Array.go
package leetcode func minimumDeviation(nums []int) int { min, max := 0, 0 for i := range nums { if nums[i]%2 == 1 { nums[i] *= 2 } if i == 0 { min = nums[i] max = nums[i] } else if nums[i] < min { min = nums[i] } else if max < nums[i] { max = nums[i] } } res := max - min for max%2 == 0 ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1675.Minimize-Deviation-in-Array/1675. Minimize Deviation in Array_test.go
leetcode/1675.Minimize-Deviation-in-Array/1675. Minimize Deviation in Array_test.go
package leetcode import ( "fmt" "testing" ) type question1675 struct { para1675 ans1675 } // para 是参数 // one 代表第一个参数 type para1675 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1675 struct { one int } func Test_Problem1675(t *testing.T) { qs := []question1675{ { para1675{[]int{1, 2, 4, 3}},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0884.Uncommon-Words-from-Two-Sentences/884. Uncommon Words from Two Sentences_test.go
leetcode/0884.Uncommon-Words-from-Two-Sentences/884. Uncommon Words from Two Sentences_test.go
package leetcode import ( "fmt" "testing" ) type question884 struct { para884 ans884 } // para 是参数 // one 代表第一个参数 type para884 struct { A string B string } // ans 是答案 // one 代表第一个答案 type ans884 struct { one []string } func Test_Problem884(t *testing.T) { qs := []question884{ { para884{"this apple is...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0884.Uncommon-Words-from-Two-Sentences/884. Uncommon Words from Two Sentences.go
leetcode/0884.Uncommon-Words-from-Two-Sentences/884. Uncommon Words from Two Sentences.go
package leetcode import "strings" func uncommonFromSentences(A string, B string) []string { m, res := map[string]int{}, []string{} for _, s := range []string{A, B} { for _, word := range strings.Split(s, " ") { m[word]++ } } for key := range m { if m[key] == 1 { res = append(res, key) } } return r...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0187.Repeated-DNA-Sequences/187. Repeated DNA Sequences_test.go
leetcode/0187.Repeated-DNA-Sequences/187. Repeated DNA Sequences_test.go
package leetcode import ( "fmt" "testing" ) type question187 struct { para187 ans187 } // para 是参数 // one 代表第一个参数 type para187 struct { one string } // ans 是答案 // one 代表第一个答案 type ans187 struct { one []string } func Test_Problem187(t *testing.T) { qs := []question187{ { para187{"AAAAACCCCCAAAAACCCCCC...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0187.Repeated-DNA-Sequences/187. Repeated DNA Sequences.go
leetcode/0187.Repeated-DNA-Sequences/187. Repeated DNA Sequences.go
package leetcode // 解法一 func findRepeatedDnaSequences(s string) []string { if len(s) < 10 { return nil } charMap, mp, result := map[uint8]uint32{'A': 0, 'C': 1, 'G': 2, 'T': 3}, make(map[uint32]int, 0), []string{} var cur uint32 for i := 0; i < 9; i++ { // 前9位,忽略 cur = cur<<2 | charMap[s[i]] } for i := 9; i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0098.Validate-Binary-Search-Tree/98. Validate Binary Search Tree.go
leetcode/0098.Validate-Binary-Search-Tree/98. Validate Binary Search Tree.go
package leetcode import ( "math" "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 * } */ // 解法一,直接按照定义比较大小,比 root 节点小的都在左边,比 root ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0098.Validate-Binary-Search-Tree/98. Validate Binary Search Tree_test.go
leetcode/0098.Validate-Binary-Search-Tree/98. Validate Binary Search Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question98 struct { para98 ans98 } // para 是参数 // one 代表第一个参数 type para98 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans98 struct { one bool } func Test_Problem98(t *testing.T) { qs := []question98{ ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0775.Global-and-Local-Inversions/775. Global and Local Inversions.go
leetcode/0775.Global-and-Local-Inversions/775. Global and Local Inversions.go
package leetcode func isIdealPermutation(A []int) bool { for i := range A { if abs(A[i]-i) > 1 { return false } } return true } func abs(a int) int { if a < 0 { return -a } return a }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0775.Global-and-Local-Inversions/775. Global and Local Inversions_test.go
leetcode/0775.Global-and-Local-Inversions/775. Global and Local Inversions_test.go
package leetcode import ( "fmt" "testing" ) type question775 struct { para775 ans775 } // para 是参数 // one 代表第一个参数 type para775 struct { A []int } // ans 是答案 // one 代表第一个答案 type ans775 struct { one bool } func Test_Problem775(t *testing.T) { qs := []question775{ { para775{[]int{1, 0, 2}}, ans775{tru...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0223.Rectangle-Area/223. Rectangle Area.go
leetcode/0223.Rectangle-Area/223. Rectangle Area.go
package leetcode func computeArea(A int, B int, C int, D int, E int, F int, G int, H int) int { X0, Y0, X1, Y1 := max(A, E), max(B, F), min(C, G), min(D, H) return area(A, B, C, D) + area(E, F, G, H) - area(X0, Y0, X1, Y1) } func area(x0, y0, x1, y1 int) int { l, h := x1-x0, y1-y0 if l <= 0 || h <= 0 { return 0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0223.Rectangle-Area/223. Rectangle Area_test.go
leetcode/0223.Rectangle-Area/223. Rectangle Area_test.go
package leetcode import ( "fmt" "testing" ) type question223 struct { para223 ans223 } // para 是参数 // one 代表第一个参数 type para223 struct { A int B int C int D int E int F int G int H int } // ans 是答案 // one 代表第一个答案 type ans223 struct { one int } func Test_Problem223(t *testing.T) { qs := []question223{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0920.Number-of-Music-Playlists/920. Number of Music Playlists_test.go
leetcode/0920.Number-of-Music-Playlists/920. Number of Music Playlists_test.go
package leetcode import ( "fmt" "testing" ) type question920 struct { para920 ans920 } // para 是参数 // one 代表第一个参数 type para920 struct { N int L int K int } // ans 是答案 // one 代表第一个答案 type ans920 struct { one int } func Test_Problem920(t *testing.T) { qs := []question920{ { para920{3, 3, 1}, ans92...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0920.Number-of-Music-Playlists/920. Number of Music Playlists.go
leetcode/0920.Number-of-Music-Playlists/920. Number of Music Playlists.go
package leetcode func numMusicPlaylists(N int, L int, K int) int { dp, mod := make([][]int, L+1), 1000000007 for i := 0; i < L+1; i++ { dp[i] = make([]int, N+1) } dp[0][0] = 1 for i := 1; i <= L; i++ { for j := 1; j <= N; j++ { dp[i][j] = (dp[i-1][j-1] * (N - (j - 1))) % mod if j > K { dp[i][j] = (d...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1470.Shuffle-the-Array/1470. Shuffle the Array_test.go
leetcode/1470.Shuffle-the-Array/1470. Shuffle the Array_test.go
package leetcode import ( "fmt" "testing" ) type question1470 struct { para1470 ans1470 } // para 是参数 // one 代表第一个参数 type para1470 struct { nums []int n int } // ans 是答案 // one 代表第一个答案 type ans1470 struct { one []int } func Test_Problem1470(t *testing.T) { qs := []question1470{ { para1470{[]int{2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1470.Shuffle-the-Array/1470. Shuffle the Array.go
leetcode/1470.Shuffle-the-Array/1470. Shuffle the Array.go
package leetcode func shuffle(nums []int, n int) []int { result := make([]int, 0) for i := 0; i < n; i++ { result = append(result, nums[i]) result = append(result, nums[n+i]) } return result }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0494.Target-Sum/494. Target Sum_test.go
leetcode/0494.Target-Sum/494. Target Sum_test.go
package leetcode import ( "fmt" "testing" ) type question494 struct { para494 ans494 } // para 是参数 // one 代表第一个参数 type para494 struct { nums []int S int } // ans 是答案 // one 代表第一个答案 type ans494 struct { one int } func Test_Problem494(t *testing.T) { qs := []question494{ { para494{[]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/0494.Target-Sum/494. Target Sum.go
leetcode/0494.Target-Sum/494. Target Sum.go
package leetcode // 解法一 DP func findTargetSumWays(nums []int, S int) int { total := 0 for _, n := range nums { total += n } if S+total < 0 || S > total || (S+total)%2 == 1 { return 0 } target := (S + total) / 2 dp := make([]int, target+1) dp[0] = 1 for _, n := range nums { for i := target; i >= n; i--...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0004.Median-of-Two-Sorted-Arrays/4. Median of Two Sorted Arrays.go
leetcode/0004.Median-of-Two-Sorted-Arrays/4. Median of Two Sorted Arrays.go
package leetcode func findMedianSortedArrays(nums1 []int, nums2 []int) float64 { // 假设 nums1 的长度小 if len(nums1) > len(nums2) { return findMedianSortedArrays(nums2, nums1) } low, high, k, nums1Mid, nums2Mid := 0, len(nums1), (len(nums1)+len(nums2)+1)>>1, 0, 0 for low <= high { // nums1: ……………… nums1[nums1Mid-...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0004.Median-of-Two-Sorted-Arrays/4. Median of Two Sorted Arrays_test.go
leetcode/0004.Median-of-Two-Sorted-Arrays/4. Median of Two Sorted Arrays_test.go
package leetcode import ( "fmt" "testing" ) type question4 struct { para4 ans4 } // para 是参数 // one 代表第一个参数 type para4 struct { nums1 []int nums2 []int } // ans 是答案 // one 代表第一个答案 type ans4 struct { one float64 } func Test_Problem4(t *testing.T) { qs := []question4{ { para4{[]int{1, 3}, []int{2}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0005.Longest-Palindromic-Substring/5. Longest Palindromic Substring.go
leetcode/0005.Longest-Palindromic-Substring/5. Longest Palindromic Substring.go
package leetcode // 解法一 Manacher's algorithm,时间复杂度 O(n),空间复杂度 O(n) func longestPalindrome(s string) string { if len(s) < 2 { return s } newS := make([]rune, 0) newS = append(newS, '#') for _, c := range s { newS = append(newS, c) newS = append(newS, '#') } // dp[i]: 以预处理字符串下标 i 为中心的回文半径(奇数长度时不包括中心) //...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0005.Longest-Palindromic-Substring/5. Longest Palindromic Substring_test.go
leetcode/0005.Longest-Palindromic-Substring/5. Longest Palindromic Substring_test.go
package leetcode import ( "fmt" "testing" ) type question5 struct { para5 ans5 } // para 是参数 // one 代表第一个参数 type para5 struct { s string } // ans 是答案 // one 代表第一个答案 type ans5 struct { one string } func Test_Problem5(t *testing.T) { qs := []question5{ { para5{"babad"}, ans5{"bab"}, }, { par...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0820.Short-Encoding-of-Words/820. Short Encoding of Words_test.go
leetcode/0820.Short-Encoding-of-Words/820. Short Encoding of Words_test.go
package leetcode import ( "fmt" "testing" ) type question820 struct { para820 ans820 } // para 是参数 // one 代表第一个参数 type para820 struct { words []string } // ans 是答案 // one 代表第一个答案 type ans820 struct { one int } func Test_Problem820(t *testing.T) { qs := []question820{ { para820{[]string{"time", "me", ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0820.Short-Encoding-of-Words/820. Short Encoding of Words.go
leetcode/0820.Short-Encoding-of-Words/820. Short Encoding of Words.go
package leetcode // 解法一 暴力 func minimumLengthEncoding(words []string) int { res, m := 0, map[string]bool{} for _, w := range words { m[w] = true } for w := range m { for i := 1; i < len(w); i++ { delete(m, w[i:]) } } for w := range m { res += len(w) + 1 } return res } // 解法二 Trie type node struct {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1984.Minimum-Difference-Between-Highest-and-Lowest-of-K-Scores/1984.Minimum Difference Between Highest and Lowest of K Scores_test.go
leetcode/1984.Minimum-Difference-Between-Highest-and-Lowest-of-K-Scores/1984.Minimum Difference Between Highest and Lowest of K Scores_test.go
package leetcode import ( "fmt" "testing" ) type question1984 struct { para1984 ans1984 } // para 是参数 type para1984 struct { nums []int k int } // ans 是答案 type ans1984 struct { ans int } func Test_Problem1984(t *testing.T) { qs := []question1984{ { para1984{[]int{90}, 1}, ans1984{0}, }, {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1984.Minimum-Difference-Between-Highest-and-Lowest-of-K-Scores/1984.Minimum Difference Between Highest and Lowest of K Scores.go
leetcode/1984.Minimum-Difference-Between-Highest-and-Lowest-of-K-Scores/1984.Minimum Difference Between Highest and Lowest of K Scores.go
package leetcode import "sort" func minimumDifference(nums []int, k int) int { sort.Ints(nums) minDiff := 100000 + 1 for i := 0; i < len(nums); i++ { if i+k-1 >= len(nums) { break } diff := nums[i+k-1] - nums[i] if diff < minDiff { minDiff = diff } } return minDiff }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0524.Longest-Word-in-Dictionary-through-Deleting/524. Longest Word in Dictionary through Deleting.go
leetcode/0524.Longest-Word-in-Dictionary-through-Deleting/524. Longest Word in Dictionary through Deleting.go
package leetcode func findLongestWord(s string, d []string) string { res := "" for i := 0; i < len(d); i++ { pointS := 0 pointD := 0 for pointS < len(s) && pointD < len(d[i]) { if s[pointS] == d[i][pointD] { pointD++ } pointS++ } if pointD == len(d[i]) && (len(res) < len(d[i]) || (len(res) == ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0524.Longest-Word-in-Dictionary-through-Deleting/524. Longest Word in Dictionary through Deleting_test.go
leetcode/0524.Longest-Word-in-Dictionary-through-Deleting/524. Longest Word in Dictionary through Deleting_test.go
package leetcode import ( "fmt" "testing" ) type question524 struct { para524 ans524 } // para 是参数 // one 代表第一个参数 type para524 struct { s string one []string } // ans 是答案 // one 代表第一个答案 type ans524 struct { one string } func Test_Problem524(t *testing.T) { qs := []question524{ { para524{"abpcplea"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0700.Search-in-a-Binary-Search-Tree/700.Search in a Binary Search Tree.go
leetcode/0700.Search-in-a-Binary-Search-Tree/700.Search in 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 searchBST(root *TreeNode, val int) *TreeNode ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0700.Search-in-a-Binary-Search-Tree/700.Search in a Binary Search Tree_test.go
leetcode/0700.Search-in-a-Binary-Search-Tree/700.Search in a Binary Search Tree_test.go
package leetcode import ( "fmt" "testing" ) type question700 struct { para700 ans700 } // para 是参数 type para700 struct { root *TreeNode val int } // ans 是答案 type ans700 struct { ans *TreeNode } func Test_Problem700(t *testing.T) { qs := []question700{ { para700{&TreeNode{Val: 4, Left: &TreeNode...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0012.Integer-to-Roman/12. Integer to Roman.go
leetcode/0012.Integer-to-Roman/12. Integer to Roman.go
package leetcode func intToRoman(num int) string { values := []int{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1} symbols := []string{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"} res, i := "", 0 for num != 0 { for values[i] > num { i++ } num -= values[i] res += symbols[i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0012.Integer-to-Roman/12. Integer to Roman_test.go
leetcode/0012.Integer-to-Roman/12. Integer to Roman_test.go
package leetcode import ( "fmt" "testing" ) type question12 struct { para12 ans12 } // para 是参数 // one 代表第一个参数 type para12 struct { one int } // ans 是答案 // one 代表第一个答案 type ans12 struct { one string } func Test_Problem12(t *testing.T) { qs := []question12{ { para12{3}, ans12{"III"}, }, { p...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0154.Find-Minimum-in-Rotated-Sorted-Array-II/154. Find Minimum in Rotated Sorted Array II_test.go
leetcode/0154.Find-Minimum-in-Rotated-Sorted-Array-II/154. Find Minimum in Rotated Sorted Array II_test.go
package leetcode import ( "fmt" "testing" ) type question154 struct { para154 ans154 } // para 是参数 // one 代表第一个参数 type para154 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans154 struct { one int } func Test_Problem154(t *testing.T) { qs := []question154{ { para154{[]int{10, 2, 10, 10, 10, 10...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0154.Find-Minimum-in-Rotated-Sorted-Array-II/154. Find Minimum in Rotated Sorted Array II.go
leetcode/0154.Find-Minimum-in-Rotated-Sorted-Array-II/154. Find Minimum in Rotated Sorted Array II.go
package leetcode func findMin154(nums []int) int { low, high := 0, len(nums)-1 for low < high { if nums[low] < nums[high] { return nums[low] } mid := low + (high-low)>>1 if nums[mid] > nums[low] { low = mid + 1 } else if nums[mid] == nums[low] { low++ } else { high = mid } } return nums[l...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups_test.go
leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups_test.go
package leetcode import ( "fmt" "testing" ) type question830 struct { para830 ans830 } // para 是参数 // one 代表第一个参数 type para830 struct { S string } // ans 是答案 // one 代表第一个答案 type ans830 struct { one [][]int } func Test_Problem830(t *testing.T) { qs := []question830{ { para830{"abbxxxxzzy"}, ans830{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups.go
leetcode/0830.Positions-of-Large-Groups/830. Positions of Large Groups.go
package leetcode func largeGroupPositions(S string) [][]int { res, end := [][]int{}, 0 for end < len(S) { start, str := end, S[end] for end < len(S) && S[end] == str { end++ } if end-start >= 3 { res = append(res, []int{start, end - 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/0554.Brick-Wall/554. Brick Wall.go
leetcode/0554.Brick-Wall/554. Brick Wall.go
package leetcode func leastBricks(wall [][]int) int { m := make(map[int]int) for _, row := range wall { sum := 0 for i := 0; i < len(row)-1; i++ { sum += row[i] m[sum]++ } } max := 0 for _, v := range m { if v > max { max = v } } return len(wall) - max }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0554.Brick-Wall/554. Brick Wall_test.go
leetcode/0554.Brick-Wall/554. Brick Wall_test.go
package leetcode import ( "fmt" "testing" ) type question554 struct { para554 ans554 } // para 是参数 // one 代表第一个参数 type para554 struct { wall [][]int } // ans 是答案 // one 代表第一个答案 type ans554 struct { one int } func Test_Problem554(t *testing.T) { qs := []question554{ { para554{[][]int{{1, 2, 2, 1}, {3,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0633.Sum-of-Square-Numbers/633. Sum of Square Numbers.go
leetcode/0633.Sum-of-Square-Numbers/633. Sum of Square Numbers.go
package leetcode import "math" func judgeSquareSum(c int) bool { low, high := 0, int(math.Sqrt(float64(c))) for low <= high { if low*low+high*high < c { low++ } else if low*low+high*high > c { high-- } else { return true } } return false }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0633.Sum-of-Square-Numbers/633. Sum of Square Numbers_test.go
leetcode/0633.Sum-of-Square-Numbers/633. Sum of Square Numbers_test.go
package leetcode import ( "fmt" "testing" ) type question633 struct { para633 ans633 } // para 是参数 // one 代表第一个参数 type para633 struct { one int } // ans 是答案 // one 代表第一个答案 type ans633 struct { one bool } func Test_Problem633(t *testing.T) { qs := []question633{ { para633{1}, ans633{true}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0283.Move-Zeroes/283. Move Zeroes.go
leetcode/0283.Move-Zeroes/283. Move Zeroes.go
package leetcode func moveZeroes(nums []int) { if len(nums) == 0 { return } j := 0 for i := 0; i < len(nums); i++ { if nums[i] != 0 { if i != j { nums[i], nums[j] = nums[j], nums[i] } j++ } } }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0283.Move-Zeroes/283. Move Zeroes_test.go
leetcode/0283.Move-Zeroes/283. Move Zeroes_test.go
package leetcode import ( "fmt" "testing" ) type question283 struct { para283 ans283 } // para 是参数 // one 代表第一个参数 type para283 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans283 struct { one []int } func Test_Problem283(t *testing.T) { qs := []question283{ { para283{[]int{1, 0, 1}}, ans283...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0483.Smallest-Good-Base/483. Smallest Good Base_test.go
leetcode/0483.Smallest-Good-Base/483. Smallest Good Base_test.go
package leetcode import ( "fmt" "testing" ) type question483 struct { para483 ans483 } // para 是参数 // one 代表第一个参数 type para483 struct { one string } // ans 是答案 // one 代表第一个答案 type ans483 struct { one string } func Test_Problem483(t *testing.T) { qs := []question483{ { para483{"13"}, ans483{"3"}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0483.Smallest-Good-Base/483. Smallest Good Base.go
leetcode/0483.Smallest-Good-Base/483. Smallest Good Base.go
package leetcode import ( "math" "math/bits" "strconv" ) func smallestGoodBase(n string) string { nVal, _ := strconv.Atoi(n) mMax := bits.Len(uint(nVal)) - 1 for m := mMax; m > 1; m-- { k := int(math.Pow(float64(nVal), 1/float64(m))) mul, sum := 1, 1 for i := 0; i < m; i++ { mul *= k sum += mul } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1239.Maximum-Length-of-a-Concatenated-String-with-Unique-Characters/1239. Maximum Length of a Concatenated String with Unique Characters.go
leetcode/1239.Maximum-Length-of-a-Concatenated-String-with-Unique-Characters/1239. Maximum Length of a Concatenated String with Unique Characters.go
package leetcode import ( "math/bits" ) func maxLength(arr []string) int { c, res := []uint32{}, 0 for _, s := range arr { var mask uint32 for _, c := range s { mask = mask | 1<<(c-'a') } if len(s) != bits.OnesCount32(mask) { // 如果字符串本身带有重复的字符,需要排除 continue } c = append(c, mask) } dfs(c, 0, 0, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1239.Maximum-Length-of-a-Concatenated-String-with-Unique-Characters/1239. Maximum Length of a Concatenated String with Unique Characters_test.go
leetcode/1239.Maximum-Length-of-a-Concatenated-String-with-Unique-Characters/1239. Maximum Length of a Concatenated String with Unique Characters_test.go
package leetcode import ( "fmt" "testing" ) type question1239 struct { para1239 ans1239 } // para 是参数 // one 代表第一个参数 type para1239 struct { arr []string } // ans 是答案 // one 代表第一个答案 type ans1239 struct { one int } func Test_Problem1239(t *testing.T) { qs := []question1239{ { para1239{[]string{"un", "i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0219.Contains-Duplicate-II/219. Contains Duplicate II.go
leetcode/0219.Contains-Duplicate-II/219. Contains Duplicate II.go
package leetcode func containsNearbyDuplicate(nums []int, k int) bool { if len(nums) <= 1 { return false } if k <= 0 { return false } record := make(map[int]bool, len(nums)) for i, n := range nums { if _, found := record[n]; found { return true } record[n] = true if len(record) == k+1 { delete(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0219.Contains-Duplicate-II/219. Contains Duplicate II_test.go
leetcode/0219.Contains-Duplicate-II/219. Contains Duplicate II_test.go
package leetcode import ( "fmt" "testing" ) type question219 struct { para219 ans219 } // para 是参数 // one 代表第一个参数 type para219 struct { one []int k int } // ans 是答案 // one 代表第一个答案 type ans219 struct { one bool } func Test_Problem219(t *testing.T) { qs := []question219{ { para219{[]int{1, 2, 3, 1},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0834.Sum-of-Distances-in-Tree/834. Sum of Distances in Tree_test.go
leetcode/0834.Sum-of-Distances-in-Tree/834. Sum of Distances in Tree_test.go
package leetcode import ( "fmt" "testing" ) type question834 struct { para834 ans834 } // para 是参数 // one 代表第一个参数 type para834 struct { N int edges [][]int } // ans 是答案 // one 代表第一个答案 type ans834 struct { one []int } func Test_Problem834(t *testing.T) { qs := []question834{ { para834{4, [][]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0834.Sum-of-Distances-in-Tree/834. Sum of Distances in Tree.go
leetcode/0834.Sum-of-Distances-in-Tree/834. Sum of Distances in Tree.go
package leetcode func sumOfDistancesInTree(N int, edges [][]int) []int { // count[i] 中存储的是以 i 为根节点,所有子树结点和根节点的总数 tree, visited, count, res := make([][]int, N), make([]bool, N), make([]int, N), make([]int, N) for _, e := range edges { i, j := e[0], e[1] tree[i] = append(tree[i], j) tree[j] = append(tree[j], i)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0224.Basic-Calculator/224. Basic Calculator.go
leetcode/0224.Basic-Calculator/224. Basic Calculator.go
package leetcode import ( "container/list" "fmt" "strconv" ) // 解法一 func calculate(s string) int { i, stack, result, sign := 0, list.New(), 0, 1 // 记录加减状态 for i < len(s) { if s[i] == ' ' { i++ } else if s[i] <= '9' && s[i] >= '0' { // 获取一段数字 base, v := 10, int(s[i]-'0') for i+1 < len(s) && s[i+1] <=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0224.Basic-Calculator/224. Basic Calculator_test.go
leetcode/0224.Basic-Calculator/224. Basic Calculator_test.go
package leetcode import ( "fmt" "testing" ) type question224 struct { para224 ans224 } // para 是参数 // one 代表第一个参数 type para224 struct { one string } // ans 是答案 // one 代表第一个答案 type ans224 struct { one int } func Test_Problem224(t *testing.T) { qs := []question224{ { para224{"1 + 1"}, ans224{2}, }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0784.Letter-Case-Permutation/784. Letter Case Permutation_test.go
leetcode/0784.Letter-Case-Permutation/784. Letter Case Permutation_test.go
package leetcode import ( "fmt" "testing" ) type question784 struct { para784 ans784 } // para 是参数 // one 代表第一个参数 type para784 struct { one string } // ans 是答案 // one 代表第一个答案 type ans784 struct { one []string } func Test_Problem784(t *testing.T) { qs := []question784{ { para784{"mQe"}, ans784{[]st...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0784.Letter-Case-Permutation/784. Letter Case Permutation.go
leetcode/0784.Letter-Case-Permutation/784. Letter Case Permutation.go
package leetcode import ( "strings" ) // 解法一,DFS 深搜 func letterCasePermutation(S string) []string { if len(S) == 0 { return []string{} } res, pos, c := []string{}, []int{}, []int{} SS := strings.ToLower(S) for i := 0; i < len(SS); i++ { if isLowerLetter(SS[i]) { pos = append(pos, i) } } for i := 0; i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0863.All-Nodes-Distance-K-in-Binary-Tree/863. All Nodes Distance K in Binary Tree_test.go
leetcode/0863.All-Nodes-Distance-K-in-Binary-Tree/863. All Nodes Distance K in Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question863 struct { para863 ans863 } // para 是参数 // one 代表第一个参数 type para863 struct { root []int target []int K int } // ans 是答案 // one 代表第一个答案 type ans863 struct { one []int } func Test_Problem863(t *te...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0863.All-Nodes-Distance-K-in-Binary-Tree/863. All Nodes Distance K in Binary Tree.go
leetcode/0863.All-Nodes-Distance-K-in-Binary-Tree/863. All Nodes Distance K 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 distanceK(root *TreeNode, target *TreeNode, K ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2167.Minimum-Time-to-Remove-All-Cars-Containing-Illegal-Goods/2167. Minimum Time to Remove All Cars Containing Illegal Goods_test.go
leetcode/2167.Minimum-Time-to-Remove-All-Cars-Containing-Illegal-Goods/2167. Minimum Time to Remove All Cars Containing Illegal Goods_test.go
package leetcode import ( "fmt" "testing" ) type question2167 struct { para2167 ans2167 } // para 是参数 // one 代表第一个参数 type para2167 struct { s string } // ans 是答案 // one 代表第一个答案 type ans2167 struct { one int } func Test_Problem2167(t *testing.T) { qs := []question2167{ { para2167{"1100101"}, ans216...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2167.Minimum-Time-to-Remove-All-Cars-Containing-Illegal-Goods/2167. Minimum Time to Remove All Cars Containing Illegal Goods.go
leetcode/2167.Minimum-Time-to-Remove-All-Cars-Containing-Illegal-Goods/2167. Minimum Time to Remove All Cars Containing Illegal Goods.go
package leetcode import "runtime/debug" // 解法一 DP func minimumTime(s string) int { suffixSum, prefixSum, res := make([]int, len(s)+1), make([]int, len(s)+1), 0 for i := len(s) - 1; i >= 0; i-- { if s[i] == '0' { suffixSum[i] = suffixSum[i+1] } else { suffixSum[i] = min(suffixSum[i+1]+2, len(s)-i) } } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb.go
leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb.go
package leetcode func decrypt(code []int, k int) []int { if k == 0 { for i := 0; i < len(code); i++ { code[i] = 0 } return code } count, sum, res := k, 0, make([]int, len(code)) if k > 0 { for i := 0; i < len(code); i++ { for j := i + 1; j < len(code); j++ { if count == 0 { break } s...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb_test.go
leetcode/1652.Defuse-the-Bomb/1652. Defuse the Bomb_test.go
package leetcode import ( "fmt" "testing" ) type question1652 struct { para1652 ans1652 } // para 是参数 // one 代表第一个参数 type para1652 struct { code []int k int } // ans 是答案 // one 代表第一个答案 type ans1652 struct { one []int } func Test_Problem1652(t *testing.T) { qs := []question1652{ { para1652{[]int{5...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List/1171. Remove Zero Sum Consecutive Nodes from Linked List.go
leetcode/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List/1171. Remove Zero Sum Consecutive Nodes from 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 removeZeroSumSublists(head *ListNode) *ListNode { // 计算累加和,和...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List/1171. Remove Zero Sum Consecutive Nodes from Linked List_test.go
leetcode/1171.Remove-Zero-Sum-Consecutive-Nodes-from-Linked-List/1171. Remove Zero Sum Consecutive Nodes from Linked List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1171 struct { para1171 ans1171 } // para 是参数 // one 代表第一个参数 type para1171 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1171 struct { one []int } func Test_Problem1171(t *testing.T) { qs := []qu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false