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/0404.Sum-of-Left-Leaves/404. Sum of Left Leaves_test.go
leetcode/0404.Sum-of-Left-Leaves/404. Sum of Left Leaves_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question404 struct { para404 ans404 } // para 是参数 // one 代表第一个参数 type para404 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans404 struct { one int } func Test_Problem404(t *testing.T) { qs := []question40...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0404.Sum-of-Left-Leaves/404. Sum of Left Leaves.go
leetcode/0404.Sum-of-Left-Leaves/404. Sum of Left Leaves.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 sumOfLeftLeaves(root *TreeNode) int { if roo...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0164.Maximum-Gap/164. Maximum Gap_test.go
leetcode/0164.Maximum-Gap/164. Maximum Gap_test.go
package leetcode import ( "fmt" "testing" ) type question164 struct { para164 ans164 } // para 是参数 // one 代表第一个参数 type para164 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans164 struct { one int } func Test_Problem164(t *testing.T) { qs := []question164{ { para164{[]int{3, 6, 9, 1}}, ans16...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0164.Maximum-Gap/164. Maximum Gap.go
leetcode/0164.Maximum-Gap/164. Maximum Gap.go
package leetcode // 解法一 快排 func maximumGap(nums []int) int { if len(nums) < 2 { return 0 } quickSort164(nums, 0, len(nums)-1) res := 0 for i := 0; i < len(nums)-1; i++ { if (nums[i+1] - nums[i]) > res { res = nums[i+1] - nums[i] } } return res } func partition164(a []int, lo, hi int) int { pivot := a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings.go
leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings.go
package leetcode func countConsistentStrings(allowed string, words []string) int { allowedMap, res, flag := map[rune]int{}, 0, true for _, str := range allowed { allowedMap[str]++ } for i := 0; i < len(words); i++ { flag = true for j := 0; j < len(words[i]); j++ { if _, ok := allowedMap[rune(words[i][j])]...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings_test.go
leetcode/1684.Count-the-Number-of-Consistent-Strings/1684. Count the Number of Consistent Strings_test.go
package leetcode import ( "fmt" "testing" ) type question1684 struct { para1684 ans1684 } // para 是参数 // one 代表第一个参数 type para1684 struct { allowed string words []string } // ans 是答案 // one 代表第一个答案 type ans1684 struct { one int } func Test_Problem1684(t *testing.T) { qs := []question1684{ { para16...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1202.Smallest-String-With-Swaps/1202. Smallest String With Swaps.go
leetcode/1202.Smallest-String-With-Swaps/1202. Smallest String With Swaps.go
package leetcode import ( "sort" "github.com/halfrost/LeetCode-Go/template" ) func smallestStringWithSwaps(s string, pairs [][]int) string { uf, res, sMap := template.UnionFind{}, []byte(s), map[int][]byte{} uf.Init(len(s)) for _, pair := range pairs { uf.Union(pair[0], pair[1]) } for i := 0; i < 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/1202.Smallest-String-With-Swaps/1202. Smallest String With Swaps_test.go
leetcode/1202.Smallest-String-With-Swaps/1202. Smallest String With Swaps_test.go
package leetcode import ( "fmt" "testing" ) type question1202 struct { para1202 ans1202 } // para 是参数 // one 代表第一个参数 type para1202 struct { s string pairs [][]int } // ans 是答案 // one 代表第一个答案 type ans1202 struct { one string } func Test_Problem1202(t *testing.T) { qs := []question1202{ { para1202...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1093.Statistics-from-a-Large-Sample/1093. Statistics from a Large Sample_test.go
leetcode/1093.Statistics-from-a-Large-Sample/1093. Statistics from a Large Sample_test.go
package leetcode import ( "fmt" "testing" ) type question1093 struct { para1093 ans1093 } // para 是参数 // one 代表第一个参数 type para1093 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1093 struct { one []float64 } func Test_Problem1093(t *testing.T) { qs := []question1093{ { para1093{[]int{0, 1, 3,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1093.Statistics-from-a-Large-Sample/1093. Statistics from a Large Sample.go
leetcode/1093.Statistics-from-a-Large-Sample/1093. Statistics from a Large Sample.go
package leetcode func sampleStats(count []int) []float64 { res := make([]float64, 5) res[0] = 255 sum := 0 for _, val := range count { sum += val } left, right := sum/2, sum/2 if (sum % 2) == 0 { right++ } pre, mode := 0, 0 for i, val := range count { if val > 0 { if i < int(res[0]) { res[0] = f...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1721.Swapping-Nodes-in-a-Linked-List/1721. Swapping Nodes in a Linked List_test.go
leetcode/1721.Swapping-Nodes-in-a-Linked-List/1721. Swapping Nodes in a Linked List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question2 struct { para2 ans2 } // para 是参数 // one 代表第一个参数 type para2 struct { head []int k int } // ans 是答案 // one 代表第一个答案 type ans2 struct { one []int } func Test_Problem2(t *testing.T) { qs := []question2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1721.Swapping-Nodes-in-a-Linked-List/1721. Swapping Nodes in a Linked List.go
leetcode/1721.Swapping-Nodes-in-a-Linked-List/1721. Swapping Nodes in a 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 swapNodes(head *ListNode, k int) *ListNode { count := 1 var a, b *L...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1208.Get-Equal-Substrings-Within-Budget/1208. Get Equal Substrings Within Budget.go
leetcode/1208.Get-Equal-Substrings-Within-Budget/1208. Get Equal Substrings Within Budget.go
package leetcode func equalSubstring(s string, t string, maxCost int) int { left, right, res := 0, -1, 0 for left < len(s) { if right+1 < len(s) && maxCost-abs(int(s[right+1]-'a')-int(t[right+1]-'a')) >= 0 { right++ maxCost -= abs(int(s[right]-'a') - int(t[right]-'a')) } else { res = max(res, right-left...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1208.Get-Equal-Substrings-Within-Budget/1208. Get Equal Substrings Within Budget_test.go
leetcode/1208.Get-Equal-Substrings-Within-Budget/1208. Get Equal Substrings Within Budget_test.go
package leetcode import ( "fmt" "testing" ) type question1208 struct { para1208 ans1208 } // para 是参数 // one 代表第一个参数 type para1208 struct { s string t string maxCost int } // ans 是答案 // one 代表第一个答案 type ans1208 struct { one int } func Test_Problem1208(t *testing.T) { qs := []question1208{ ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0402.Remove-K-Digits/402. Remove K Digits_test.go
leetcode/0402.Remove-K-Digits/402. Remove K Digits_test.go
package leetcode import ( "fmt" "testing" ) type question402 struct { para402 ans402 } // para 是参数 // one 代表第一个参数 type para402 struct { num string k int } // ans 是答案 // one 代表第一个答案 type ans402 struct { one string } func Test_Problem402(t *testing.T) { qs := []question402{ { para402{"10", 1}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0402.Remove-K-Digits/402. Remove K Digits.go
leetcode/0402.Remove-K-Digits/402. Remove K Digits.go
package leetcode func removeKdigits(num string, k int) string { if k == len(num) { return "0" } res := []byte{} for i := 0; i < len(num); i++ { c := num[i] for k > 0 && len(res) > 0 && c < res[len(res)-1] { res = res[:len(res)-1] k-- } res = append(res, c) } res = res[:len(res)-k] // trim leadi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0703.Kth-Largest-Element-in-a-Stream/703. Kth Largest Element in a Stream.go
leetcode/0703.Kth-Largest-Element-in-a-Stream/703. Kth Largest Element in a Stream.go
package leetcode import ( "container/heap" "sort" ) type KthLargest struct { sort.IntSlice k int } func Constructor(k int, nums []int) KthLargest { kl := KthLargest{k: k} for _, val := range nums { kl.Add(val) } return kl } func (kl *KthLargest) Push(v interface{}) { kl.IntSlice = append(kl.IntSlice, v.(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0703.Kth-Largest-Element-in-a-Stream/703. Kth Largest Element in a Stream_test.go
leetcode/0703.Kth-Largest-Element-in-a-Stream/703. Kth Largest Element in a Stream_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem703(t *testing.T) { obj := Constructor(3, []int{4, 5, 8, 2}) fmt.Printf("Add 7 = %v\n", obj.Add(3)) fmt.Printf("Add 7 = %v\n", obj.Add(5)) fmt.Printf("Add 7 = %v\n", obj.Add(10)) fmt.Printf("Add 7 = %v\n", obj.Add(9)) fmt.Printf("Add 7 = %v\n", obj....
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1010.Pairs-of-Songs-With-Total-Durations-Divisible-by-60/1010. Pairs of Songs With Total Durations Divisible by 60.go
leetcode/1010.Pairs-of-Songs-With-Total-Durations-Divisible-by-60/1010. Pairs of Songs With Total Durations Divisible by 60.go
package leetcode func numPairsDivisibleBy60(time []int) int { counts := make([]int, 60) for _, v := range time { v %= 60 counts[v]++ } res := 0 for i := 1; i < len(counts)/2; i++ { res += counts[i] * counts[60-i] } res += (counts[0] * (counts[0] - 1)) / 2 res += (counts[30] * (counts[30] - 1)) / 2 retur...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1010.Pairs-of-Songs-With-Total-Durations-Divisible-by-60/1010. Pairs of Songs With Total Durations Divisible by 60_test.go
leetcode/1010.Pairs-of-Songs-With-Total-Durations-Divisible-by-60/1010. Pairs of Songs With Total Durations Divisible by 60_test.go
package leetcode import ( "fmt" "testing" ) type question1010 struct { para1010 ans1010 } // para 是参数 // one 代表第一个参数 type para1010 struct { time []int } // ans 是答案 // one 代表第一个答案 type ans1010 struct { one int } func Test_Problem1010(t *testing.T) { qs := []question1010{ { para1010{[]int{30, 20, 150, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs_test.go
leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs_test.go
package leetcode import ( "fmt" "testing" ) type question1679 struct { para1679 ans1679 } // para 是参数 // one 代表第一个参数 type para1679 struct { nums []int k int } // ans 是答案 // one 代表第一个答案 type ans1679 struct { one int } func Test_Problem1679(t *testing.T) { qs := []question1679{ { para1679{[]int{1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs.go
leetcode/1679.Max-Number-of-K-Sum-Pairs/1679. Max Number of K-Sum Pairs.go
package leetcode // 解法一 优化版 func maxOperations(nums []int, k int) int { counter, res := make(map[int]int), 0 for _, n := range nums { counter[n]++ } if (k & 1) == 0 { res += counter[k>>1] >> 1 // 能够由 2 个相同的数构成 k 的组合已经都排除出去了,剩下的一个单独的也不能组成 k 了 // 所以这里要把它的频次置为 0 。如果这里不置为 0,下面代码判断逻辑还需要考虑重复使用数字的情况 counter[k>>...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1235.Maximum-Profit-in-Job-Scheduling/1235. Maximum Profit in Job Scheduling.go
leetcode/1235.Maximum-Profit-in-Job-Scheduling/1235. Maximum Profit in Job Scheduling.go
package leetcode import "sort" type job struct { startTime int endTime int profit int } func jobScheduling(startTime []int, endTime []int, profit []int) int { jobs, dp := []job{}, make([]int, len(startTime)) for i := 0; i < len(startTime); i++ { jobs = append(jobs, job{startTime: startTime[i], endTime: e...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1235.Maximum-Profit-in-Job-Scheduling/1235. Maximum Profit in Job Scheduling_test.go
leetcode/1235.Maximum-Profit-in-Job-Scheduling/1235. Maximum Profit in Job Scheduling_test.go
package leetcode import ( "fmt" "testing" ) type question1235 struct { para1235 ans1235 } // para 是参数 // one 代表第一个参数 type para1235 struct { startTime []int endTime []int profit []int } // ans 是答案 // one 代表第一个答案 type ans1235 struct { one int } func Test_Problem1235(t *testing.T) { qs := []question123...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0232.Implement-Queue-using-Stacks/232. Implement Queue using Stacks_test.go
leetcode/0232.Implement-Queue-using-Stacks/232. Implement Queue using Stacks_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem232(t *testing.T) { obj := Constructor232() fmt.Printf("obj = %v\n", obj) obj.Push(2) fmt.Printf("obj = %v\n", obj) obj.Push(10) fmt.Printf("obj = %v\n", obj) param2 := obj.Pop() fmt.Printf("param_2 = %v\n", param2) param3 := obj.Peek() fmt.Prin...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0232.Implement-Queue-using-Stacks/232. Implement Queue using Stacks.go
leetcode/0232.Implement-Queue-using-Stacks/232. Implement Queue using Stacks.go
package leetcode type MyQueue struct { Stack *[]int Queue *[]int } /** Initialize your data structure here. */ func Constructor232() MyQueue { tmp1, tmp2 := []int{}, []int{} return MyQueue{Stack: &tmp1, Queue: &tmp2} } /** Push element x to the back of queue. */ func (this *MyQueue) Push(x int) { *this.Stack = ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0864.Shortest-Path-to-Get-All-Keys/864. Shortest Path to Get All Keys.go
leetcode/0864.Shortest-Path-to-Get-All-Keys/864. Shortest Path to Get All Keys.go
package leetcode import ( "math" "strings" ) var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } // 解法一 BFS,利用状态压缩来过滤筛选状态 func shortestPathAllKeys(grid []string) int { if len(grid) == 0 { return 0 } board, visited, startx, starty, res, fullKeys := make([][]byte, len(grid)), make([][][]bool, len(grid)),...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0864.Shortest-Path-to-Get-All-Keys/864. Shortest Path to Get All Keys_test.go
leetcode/0864.Shortest-Path-to-Get-All-Keys/864. Shortest Path to Get All Keys_test.go
package leetcode import ( "fmt" "testing" ) type question864 struct { para864 ans864 } // para 是参数 // one 代表第一个参数 type para864 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans864 struct { one int } func Test_Problem864(t *testing.T) { qs := []question864{ { para864{[]string{".##..##..B", "#...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0705.Design-HashSet/705. Design HashSet.go
leetcode/0705.Design-HashSet/705. Design HashSet.go
package leetcode type MyHashSet struct { data []bool } /** Initialize your data structure here. */ func Constructor705() MyHashSet { return MyHashSet{ data: make([]bool, 1000001), } } func (this *MyHashSet) Add(key int) { this.data[key] = true } func (this *MyHashSet) Remove(key int) { this.data[key] = false...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0705.Design-HashSet/705. Design HashSet_test.go
leetcode/0705.Design-HashSet/705. Design HashSet_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem705(t *testing.T) { obj := Constructor705() obj.Add(7) fmt.Printf("Contains 7 = %v\n", obj.Contains(7)) obj.Remove(10) fmt.Printf("Contains 10 = %v\n", obj.Contains(10)) obj.Add(20) fmt.Printf("Contains 20 = %v\n", obj.Contains(20)) obj.Remove(30)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0035.Search-Insert-Position/35. Search Insert Position.go
leetcode/0035.Search-Insert-Position/35. Search Insert Position.go
package leetcode func searchInsert(nums []int, target int) int { low, high := 0, len(nums)-1 for low <= high { mid := low + (high-low)>>1 if nums[mid] >= target { high = mid - 1 } else { if (mid == len(nums)-1) || (nums[mid+1] >= target) { return mid + 1 } low = mid + 1 } } return 0 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0035.Search-Insert-Position/35. Search Insert Position_test.go
leetcode/0035.Search-Insert-Position/35. Search Insert Position_test.go
package leetcode import ( "fmt" "testing" ) type question35 struct { para35 ans35 } // para 是参数 // one 代表第一个参数 type para35 struct { nums []int target int } // ans 是答案 // one 代表第一个答案 type ans35 struct { one int } func Test_Problem35(t *testing.T) { qs := []question35{ { para35{[]int{1, 3, 5, 6}, 5}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1629.Slowest-Key/1629. Slowest Key.go
leetcode/1629.Slowest-Key/1629. Slowest Key.go
package leetcode func slowestKey(releaseTimes []int, keysPressed string) byte { longestDuration, key := releaseTimes[0], keysPressed[0] for i := 1; i < len(releaseTimes); i++ { duration := releaseTimes[i] - releaseTimes[i-1] if duration > longestDuration { longestDuration = duration key = keysPressed[i] ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1629.Slowest-Key/1629. Slowest Key_test.go
leetcode/1629.Slowest-Key/1629. Slowest Key_test.go
package leetcode import ( "fmt" "testing" ) type question1629 struct { para1629 ans1629 } // para 是参数 // one 代表第一个参数 type para1629 struct { releaseTimes []int keysPressed string } // ans 是答案 // one 代表第一个答案 type ans1629 struct { one byte } func Test_Problem1629(t *testing.T) { qs := []question1629{ { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0707.Design-Linked-List/707. Design Linked List_test.go
leetcode/0707.Design-Linked-List/707. Design Linked List_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem707(t *testing.T) { obj := Constructor() fmt.Printf("obj = %v\n", MList2Ints(&obj)) param1 := obj.Get(1) fmt.Printf("param_1 = %v obj = %v\n", param1, MList2Ints(&obj)) obj.AddAtHead(38) fmt.Printf("obj = %v\n", MList2Ints(&obj)) obj.AddAtHead(45) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0707.Design-Linked-List/707. Design Linked List.go
leetcode/0707.Design-Linked-List/707. Design Linked List.go
package leetcode type MyLinkedList struct { head *Node } type Node struct { Val int Next *Node Prev *Node } /** Initialize your data structure here. */ func Constructor() MyLinkedList { return MyLinkedList{} } /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */ fu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0342.Power-of-Four/342. Power of Four_test.go
leetcode/0342.Power-of-Four/342. Power of Four_test.go
package leetcode import ( "fmt" "testing" ) type question342 struct { para342 ans342 } // para 是参数 // one 代表第一个参数 type para342 struct { one int } // ans 是答案 // one 代表第一个答案 type ans342 struct { one bool } func Test_Problem342(t *testing.T) { qs := []question342{ { para342{16}, ans342{true}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0342.Power-of-Four/342. Power of Four.go
leetcode/0342.Power-of-Four/342. Power of Four.go
package leetcode // 解法一 数论 func isPowerOfFour(num int) bool { return num > 0 && (num&(num-1)) == 0 && (num-1)%3 == 0 } // 解法二 循环 func isPowerOfFour1(num int) bool { for num >= 4 { if num%4 == 0 { num = num / 4 } else { return false } } return num == 1 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0080.Remove-Duplicates-from-Sorted-Array-II/80. Remove Duplicates from Sorted Array II_test.go
leetcode/0080.Remove-Duplicates-from-Sorted-Array-II/80. Remove Duplicates from Sorted Array II_test.go
package leetcode import ( "fmt" "testing" ) type question80 struct { para80 ans80 } // para 是参数 // one 代表第一个参数 type para80 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans80 struct { one int } func Test_Problem80(t *testing.T) { qs := []question80{ { para80{[]int{1, 1, 2}}, ans80{3}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0080.Remove-Duplicates-from-Sorted-Array-II/80. Remove Duplicates from Sorted Array II.go
leetcode/0080.Remove-Duplicates-from-Sorted-Array-II/80. Remove Duplicates from Sorted Array II.go
package leetcode func removeDuplicates(nums []int) int { slow := 0 for fast, v := range nums { if fast < 2 || nums[slow-2] != v { nums[slow] = v slow++ } } return slow }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0153.Find-Minimum-in-Rotated-Sorted-Array/153. Find Minimum in Rotated Sorted Array_test.go
leetcode/0153.Find-Minimum-in-Rotated-Sorted-Array/153. Find Minimum in Rotated Sorted Array_test.go
package leetcode import ( "fmt" "testing" ) type question153 struct { para153 ans153 } // para 是参数 // one 代表第一个参数 type para153 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans153 struct { one int } func Test_Problem153(t *testing.T) { qs := []question153{ { para153{[]int{5, 1, 2, 3, 4}}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0153.Find-Minimum-in-Rotated-Sorted-Array/153. Find Minimum in Rotated Sorted Array.go
leetcode/0153.Find-Minimum-in-Rotated-Sorted-Array/153. Find Minimum in Rotated Sorted Array.go
package leetcode // 解法一 二分 func findMin(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 { high = mid } } return nums[low] } // 解法二 二分 func findMin1(nums []...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0242.Valid-Anagram/242. Valid Anagram_test.go
leetcode/0242.Valid-Anagram/242. Valid Anagram_test.go
package leetcode import ( "fmt" "testing" ) type question242 struct { para242 ans242 } // para 是参数 // one 代表第一个参数 type para242 struct { one string two string } // ans 是答案 // one 代表第一个答案 type ans242 struct { one bool } func Test_Problem242(t *testing.T) { qs := []question242{ { para242{"", ""}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0242.Valid-Anagram/242. Valid Anagram.go
leetcode/0242.Valid-Anagram/242. Valid Anagram.go
package leetcode // 解法一 func isAnagram(s string, t string) bool { alphabet := make([]int, 26) sBytes := []byte(s) tBytes := []byte(t) if len(sBytes) != len(tBytes) { return false } for i := 0; i < len(sBytes); i++ { alphabet[sBytes[i]-'a']++ } for i := 0; i < len(tBytes); i++ { alphabet[tBytes[i]-'a']-- ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1104.Path-In-Zigzag-Labelled-Binary-Tree/1104.Path In Zigzag Labelled Binary Tree_test.go
leetcode/1104.Path-In-Zigzag-Labelled-Binary-Tree/1104.Path In Zigzag Labelled Binary Tree_test.go
package leetcode import ( "fmt" "testing" ) type question1104 struct { para1104 ans1104 } // para 是参数 type para1104 struct { label int } // ans 是答案 type ans1104 struct { ans []int } func Test_Problem1104(t *testing.T) { qs := []question1104{ { para1104{14}, ans1104{[]int{1, 3, 4, 14}}, }, { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1104.Path-In-Zigzag-Labelled-Binary-Tree/1104.Path In Zigzag Labelled Binary Tree.go
leetcode/1104.Path-In-Zigzag-Labelled-Binary-Tree/1104.Path In Zigzag Labelled Binary Tree.go
package leetcode func pathInZigZagTree(label int) []int { level := getLevel(label) ans := []int{label} curIndex := label - (1 << level) parent := 0 for level >= 1 { parent, curIndex = getParent(curIndex, level) ans = append(ans, parent) level-- } ans = reverse(ans) return ans } func getLevel(label int) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array.go
leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array.go
package leetcode func runningSum(nums []int) []int { dp := make([]int, len(nums)+1) dp[0] = 0 for i := 1; i <= len(nums); i++ { dp[i] = dp[i-1] + nums[i-1] } return dp[1:] }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array_test.go
leetcode/1480.Running-Sum-of-1d-Array/1480. Running Sum of 1d Array_test.go
package leetcode import ( "fmt" "testing" ) type question1480 struct { para1480 ans1480 } // para 是参数 // one 代表第一个参数 type para1480 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1480 struct { one []int } func Test_Problem1480(t *testing.T) { qs := []question1480{ { para1480{[]int{1, 2, 3, 4}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0823.Binary-Trees-With-Factors/823. Binary Trees With Factors_test.go
leetcode/0823.Binary-Trees-With-Factors/823. Binary Trees With Factors_test.go
package leetcode import ( "fmt" "testing" ) type question823 struct { para823 ans823 } // para 是参数 // one 代表第一个参数 type para823 struct { arr []int } // ans 是答案 // one 代表第一个答案 type ans823 struct { one int } func Test_Problem823(t *testing.T) { qs := []question823{ { para823{[]int{2, 4}}, ans823{3}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0823.Binary-Trees-With-Factors/823. Binary Trees With Factors.go
leetcode/0823.Binary-Trees-With-Factors/823. Binary Trees With Factors.go
package leetcode import ( "sort" ) const mod = 1e9 + 7 // 解法一 DFS func numFactoredBinaryTrees(arr []int) int { sort.Ints(arr) numDict := map[int]bool{} for _, num := range arr { numDict[num] = true } dict, res := make(map[int][][2]int), 0 for i, num := range arr { for j := i; j < len(arr) && num*arr[j] <=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0147.Insertion-Sort-List/147. Insertion Sort List.go
leetcode/0147.Insertion-Sort-List/147. Insertion Sort 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 insertionSortList(head *ListNode) *ListNode { if head == nil { ret...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0147.Insertion-Sort-List/147. Insertion Sort List_test.go
leetcode/0147.Insertion-Sort-List/147. Insertion Sort List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question147 struct { para147 ans147 } // para 是参数 // one 代表第一个参数 type para147 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans147 struct { one []int } func Test_Problem147(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/0350.Intersection-of-Two-Arrays-II/350. Intersection of Two Arrays II_test.go
leetcode/0350.Intersection-of-Two-Arrays-II/350. Intersection of Two Arrays II_test.go
package leetcode import ( "fmt" "testing" ) type question350 struct { para350 ans350 } // para 是参数 // one 代表第一个参数 type para350 struct { one []int another []int } // ans 是答案 // one 代表第一个答案 type ans350 struct { one []int } func Test_Problem350(t *testing.T) { qs := []question350{ { para350{[]int{}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0350.Intersection-of-Two-Arrays-II/350. Intersection of Two Arrays II.go
leetcode/0350.Intersection-of-Two-Arrays-II/350. Intersection of Two Arrays II.go
package leetcode func intersect(nums1 []int, nums2 []int) []int { m := map[int]int{} var res []int for _, n := range nums1 { m[n]++ } for _, n := range nums2 { if m[n] > 0 { res = append(res, n) m[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/0841.Keys-and-Rooms/841. Keys and Rooms_test.go
leetcode/0841.Keys-and-Rooms/841. Keys and Rooms_test.go
package leetcode import ( "fmt" "testing" ) type question841 struct { para841 ans841 } // para 是参数 // one 代表第一个参数 type para841 struct { rooms [][]int } // ans 是答案 // one 代表第一个答案 type ans841 struct { one bool } func Test_Problem841(t *testing.T) { qs := []question841{ { para841{[][]int{{1}, {2}, {3}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0841.Keys-and-Rooms/841. Keys and Rooms.go
leetcode/0841.Keys-and-Rooms/841. Keys and Rooms.go
package leetcode func canVisitAllRooms(rooms [][]int) bool { visited := make(map[int]bool) visited[0] = true dfsVisitAllRooms(rooms, visited, 0) return len(rooms) == len(visited) } func dfsVisitAllRooms(es [][]int, visited map[int]bool, from int) { for _, to := range es[from] { if visited[to] { continue }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0528.Random-Pick-with-Weight/528. Random Pick with Weight.go
leetcode/0528.Random-Pick-with-Weight/528. Random Pick with Weight.go
package leetcode import ( "math/rand" ) // Solution528 define type Solution528 struct { prefixSum []int } // Constructor528 define func Constructor528(w []int) Solution528 { prefixSum := make([]int, len(w)) for i, e := range w { if i == 0 { prefixSum[i] = e continue } prefixSum[i] = prefixSum[i-1] + ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0528.Random-Pick-with-Weight/528. Random Pick with Weight_test.go
leetcode/0528.Random-Pick-with-Weight/528. Random Pick with Weight_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem528(t *testing.T) { w := []int{1, 3} sol := Constructor528(w) fmt.Printf("1.PickIndex = %v\n", sol.PickIndex()) fmt.Printf("2.PickIndex = %v\n", sol.PickIndex()) fmt.Printf("3.PickIndex = %v\n", sol.PickIndex()) fmt.Printf("4.PickIndex = %v\n", sol....
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1260.Shift-2D-Grid/1260. Shift 2D Grid.go
leetcode/1260.Shift-2D-Grid/1260. Shift 2D Grid.go
package leetcode func shiftGrid(grid [][]int, k int) [][]int { x, y := len(grid[0]), len(grid) newGrid := make([][]int, y) for i := 0; i < y; i++ { newGrid[i] = make([]int, x) } for i := 0; i < y; i++ { for j := 0; j < x; j++ { ny := (k / x) + i if (j + (k % x)) >= x { ny++ } newGrid[ny%y][(j+...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1260.Shift-2D-Grid/1260. Shift 2D Grid_test.go
leetcode/1260.Shift-2D-Grid/1260. Shift 2D Grid_test.go
package leetcode import ( "fmt" "testing" ) type question1260 struct { para1260 ans1260 } // para 是参数 // one 代表第一个参数 type para1260 struct { grid [][]int k int } // ans 是答案 // one 代表第一个答案 type ans1260 struct { one [][]int } func Test_Problem1260(t *testing.T) { qs := []question1260{ { para1260{[][...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1763.Longest-Nice-Substring/1763. Longest Nice Substring.go
leetcode/1763.Longest-Nice-Substring/1763. Longest Nice Substring.go
package leetcode import "unicode" // 解法一 分治,时间复杂度 O(n) func longestNiceSubstring(s string) string { if len(s) < 2 { return "" } chars := map[rune]int{} for _, r := range s { chars[r]++ } for i := 0; i < len(s); i++ { r := rune(s[i]) _, u := chars[unicode.ToUpper(r)] _, l := chars[unicode.ToLower(r)]...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1763.Longest-Nice-Substring/1763. Longest Nice Substring_test.go
leetcode/1763.Longest-Nice-Substring/1763. Longest Nice Substring_test.go
package leetcode import ( "fmt" "testing" ) type question1763 struct { para1763 ans1763 } // para 是参数 // one 代表第一个参数 type para1763 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1763 struct { one string } func Test_Problem1763(t *testing.T) { qs := []question1763{ { para1763{"YazaAay"}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0001.Two-Sum/1. Two Sum_test.go
leetcode/0001.Two-Sum/1. Two Sum_test.go
package leetcode import ( "fmt" "testing" ) type question1 struct { para1 ans1 } // para 是参数 // one 代表第一个参数 type para1 struct { nums []int target int } // ans 是答案 // one 代表第一个答案 type ans1 struct { one []int } func Test_Problem1(t *testing.T) { qs := []question1{ { para1{[]int{3, 2, 4}, 6}, ans1{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0001.Two-Sum/1. Two Sum.go
leetcode/0001.Two-Sum/1. Two Sum.go
package leetcode func twoSum(nums []int, target int) []int { m := make(map[int]int) for k, v := range nums { if idx, ok := m[target-v]; ok { return []int{idx, k} } m[v] = k } return nil }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0594.Longest-Harmonious-Subsequence/594. Longest Harmonious Subsequence.go
leetcode/0594.Longest-Harmonious-Subsequence/594. Longest Harmonious Subsequence.go
package leetcode func findLHS(nums []int) int { if len(nums) < 2 { return 0 } res := make(map[int]int, len(nums)) for _, num := range nums { if _, exist := res[num]; exist { res[num]++ continue } res[num] = 1 } longest := 0 for k, c := range res { if n, exist := res[k+1]; exist { if c+n > lon...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0594.Longest-Harmonious-Subsequence/594. Longest Harmonious Subsequence_test.go
leetcode/0594.Longest-Harmonious-Subsequence/594. Longest Harmonious Subsequence_test.go
package leetcode import ( "fmt" "testing" ) type question594 struct { para594 ans594 } // para 是参数 // one 代表第一个参数 type para594 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans594 struct { one int } func Test_Problem594(t *testing.T) { qs := []question594{ { para594{[]int{1, 3, 2, 2, 5, 2, 3, 7...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0753.Cracking-the-Safe/753. Cracking the Safe.go
leetcode/0753.Cracking-the-Safe/753. Cracking the Safe.go
package leetcode import "math" const number = "0123456789" func crackSafe(n int, k int) string { if n == 1 { return number[:k] } visit, total := map[string]bool{}, int(math.Pow(float64(k), float64(n))) str := make([]byte, 0, total+n-1) for i := 1; i != n; i++ { str = append(str, '0') } dfsCrackSafe(total,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0753.Cracking-the-Safe/753. Cracking the Safe_test.go
leetcode/0753.Cracking-the-Safe/753. Cracking the Safe_test.go
package leetcode import ( "fmt" "testing" ) type question753 struct { para753 ans753 } // para 是参数 // one 代表第一个参数 type para753 struct { n int k int } // ans 是答案 // one 代表第一个答案 type ans753 struct { one string } func Test_Problem753(t *testing.T) { qs := []question753{ { para753{1, 2}, ans753{"01"}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0728.Self-Dividing-Numbers/728.Self Dividing Numbers_test.go
leetcode/0728.Self-Dividing-Numbers/728.Self Dividing Numbers_test.go
package leetcode import ( "fmt" "testing" ) type question728 struct { para728 ans728 } // para 是参数 type para728 struct { left int right int } // ans 是答案 type ans728 struct { ans []int } func Test_Problem728(t *testing.T) { qs := []question728{ { para728{1, 22}, ans728{[]int{1, 2, 3, 4, 5, 6, 7, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0728.Self-Dividing-Numbers/728.Self Dividing Numbers.go
leetcode/0728.Self-Dividing-Numbers/728.Self Dividing Numbers.go
package leetcode func selfDividingNumbers(left int, right int) []int { var ans []int for num := left; num <= right; num++ { if selfDividingNum(num) { ans = append(ans, num) } } return ans } func selfDividingNum(num int) bool { for d := num; d > 0; d = d / 10 { reminder := d % 10 if reminder == 0 { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1305.All-Elements-in-Two-Binary-Search-Trees/1305. All Elements in Two Binary Search Trees_test.go
leetcode/1305.All-Elements-in-Two-Binary-Search-Trees/1305. All Elements in Two Binary Search Trees_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1305 struct { para1305 ans1305 } // para 是参数 // one 代表第一个参数 type para1305 struct { root1 []int root2 []int } // ans 是答案 // one 代表第一个答案 type ans1305 struct { one []int } func Test_Problem1305(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/1305.All-Elements-in-Two-Binary-Search-Trees/1305. All Elements in Two Binary Search Trees.go
leetcode/1305.All-Elements-in-Two-Binary-Search-Trees/1305. All Elements in Two Binary Search Trees.go
package leetcode import ( "sort" "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ // 解法一 合并排序 func getAllElements(root1 *Tr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0852.Peak-Index-in-a-Mountain-Array/852. Peak Index in a Mountain Array_test.go
leetcode/0852.Peak-Index-in-a-Mountain-Array/852. Peak Index in a Mountain Array_test.go
package leetcode import ( "fmt" "testing" ) type question852 struct { para852 ans852 } // para 是参数 // one 代表第一个参数 type para852 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans852 struct { one int } func Test_Problem852(t *testing.T) { qs := []question852{ { para852{[]int{0, 1, 0}}, ans852{1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0852.Peak-Index-in-a-Mountain-Array/852. Peak Index in a Mountain Array.go
leetcode/0852.Peak-Index-in-a-Mountain-Array/852. Peak Index in a Mountain Array.go
package leetcode // 解法一 二分 func peakIndexInMountainArray(A []int) int { low, high := 0, len(A)-1 for low <= high { mid := low + (high-low)>>1 if A[mid] > A[mid+1] && A[mid] > A[mid-1] { return mid } if A[mid] > A[mid+1] && A[mid] < A[mid-1] { high = mid - 1 } if A[mid] < A[mid+1] && A[mid] > A[mid-...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0778.Swim-in-Rising-Water/778. Swim in Rising Water_test.go
leetcode/0778.Swim-in-Rising-Water/778. Swim in Rising Water_test.go
package leetcode import ( "fmt" "testing" ) type question778 struct { para778 ans778 } // para 是参数 // one 代表第一个参数 type para778 struct { grid [][]int } // ans 是答案 // one 代表第一个答案 type ans778 struct { one int } func Test_Problem778(t *testing.T) { qs := []question778{ { para778{[][]int{{0, 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/0778.Swim-in-Rising-Water/778. Swim in Rising Water.go
leetcode/0778.Swim-in-Rising-Water/778. Swim in Rising Water.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) // 解法一 DFS + 二分 func swimInWater(grid [][]int) int { row, col, flags, minWait, maxWait := len(grid), len(grid[0]), make([][]int, len(grid)), 0, 0 for i, row := range grid { flags[i] = make([]int, len(row)) for j := 0; j < col; j++ { flag...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1073.Adding-Two-Negabinary-Numbers/1073. Adding Two Negabinary Numbers.go
leetcode/1073.Adding-Two-Negabinary-Numbers/1073. Adding Two Negabinary Numbers.go
package leetcode // 解法一 模拟进位 func addNegabinary(arr1 []int, arr2 []int) []int { carry, ans := 0, []int{} for i, j := len(arr1)-1, len(arr2)-1; i >= 0 || j >= 0 || carry != 0; { if i >= 0 { carry += arr1[i] i-- } if j >= 0 { carry += arr2[j] j-- } ans = append([]int{carry & 1}, ans...) carry =...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1073.Adding-Two-Negabinary-Numbers/1073. Adding Two Negabinary Numbers_test.go
leetcode/1073.Adding-Two-Negabinary-Numbers/1073. Adding Two Negabinary Numbers_test.go
package leetcode import ( "fmt" "testing" ) type question1073 struct { para1073 ans1073 } // para 是参数 // one 代表第一个参数 type para1073 struct { arr1 []int arr2 []int } // ans 是答案 // one 代表第一个答案 type ans1073 struct { one []int } func Test_Problem1073(t *testing.T) { qs := []question1073{ { para1073{[]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0710.Random-Pick-with-Blacklist/710. Random Pick with Blacklist_test.go
leetcode/0710.Random-Pick-with-Blacklist/710. Random Pick with Blacklist_test.go
package leetcode import ( "fmt" "testing" ) type question710 struct { para710 ans710 } // para 是参数 // one 代表第一个参数 type para710 struct { n int blackList []int times int } // ans 是答案 // one 代表第一个答案 type ans710 struct { one []int } func Test_Problem710(t *testing.T) { qs := []question710{ { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0710.Random-Pick-with-Blacklist/710. Random Pick with Blacklist.go
leetcode/0710.Random-Pick-with-Blacklist/710. Random Pick with Blacklist.go
package leetcode import "math/rand" type Solution struct { M int BlackMap map[int]int } func Constructor710(N int, blacklist []int) Solution { blackMap := map[int]int{} for i := 0; i < len(blacklist); i++ { blackMap[blacklist[i]] = 1 } M := N - len(blacklist) for _, value := range blacklist { if va...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0127.Word-Ladder/127. Word Ladder.go
leetcode/0127.Word-Ladder/127. Word Ladder.go
package leetcode func ladderLength(beginWord string, endWord string, wordList []string) int { wordMap, que, depth := getWordMap(wordList, beginWord), []string{beginWord}, 0 for len(que) > 0 { depth++ qlen := len(que) for i := 0; i < qlen; i++ { word := que[0] que = que[1:] candidates := getCandidates(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0127.Word-Ladder/127. Word Ladder_test.go
leetcode/0127.Word-Ladder/127. Word Ladder_test.go
package leetcode import ( "fmt" "testing" ) type question127 struct { para127 ans127 } // para 是参数 // one 代表第一个参数 type para127 struct { b string e string w []string } // ans 是答案 // one 代表第一个答案 type ans127 struct { one int } func Test_Problem127(t *testing.T) { qs := []question127{ { para127{"hit", "...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0003.Longest-Substring-Without-Repeating-Characters/3. Longest Substring Without Repeating Characters.go
leetcode/0003.Longest-Substring-Without-Repeating-Characters/3. Longest Substring Without Repeating Characters.go
package leetcode // 解法一 位图 func lengthOfLongestSubstring(s string) int { if len(s) == 0 { return 0 } var bitSet [256]bool result, left, right := 0, 0, 0 for left < len(s) { // 右侧字符对应的 bitSet 被标记 true,说明此字符在 X 位置重复,需要左侧向前移动,直到将 X 标记为 false if bitSet[s[right]] { bitSet[s[left]] = false left++ } else {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0003.Longest-Substring-Without-Repeating-Characters/3. Longest Substring Without Repeating Characters_test.go
leetcode/0003.Longest-Substring-Without-Repeating-Characters/3. Longest Substring Without Repeating Characters_test.go
package leetcode import ( "fmt" "testing" ) type question3 struct { para3 ans3 } // para 是参数 // one 代表第一个参数 type para3 struct { s string } // ans 是答案 // one 代表第一个答案 type ans3 struct { one int } func Test_Problem3(t *testing.T) { qs := []question3{ { para3{"abcabcbb"}, ans3{3}, }, { para3{"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0704.Binary-Search/704. Binary Search.go
leetcode/0704.Binary-Search/704. Binary Search.go
package leetcode func search704(nums []int, target int) int { low, high := 0, len(nums)-1 for low <= high { mid := low + (high-low)>>1 if nums[mid] == target { return mid } else if nums[mid] > target { high = mid - 1 } else { low = mid + 1 } } return -1 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0704.Binary-Search/704. Binary Search_test.go
leetcode/0704.Binary-Search/704. Binary Search_test.go
package leetcode import ( "fmt" "testing" ) type question704 struct { para704 ans704 } // para 是参数 // one 代表第一个参数 type para704 struct { nums []int target int } // ans 是答案 // one 代表第一个答案 type ans704 struct { one int } func Test_Problem704(t *testing.T) { qs := []question704{ { para704{[]int{-1, 0, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1185.Day-of-the-Week/1185. Day of the Week_test.go
leetcode/1185.Day-of-the-Week/1185. Day of the Week_test.go
package leetcode import ( "fmt" "testing" ) type question1185 struct { para1185 ans1185 } // para 是参数 // one 代表第一个参数 type para1185 struct { day int month int year int } // ans 是答案 // one 代表第一个答案 type ans1185 struct { one string } func Test_Problem1185(t *testing.T) { qs := []question1185{ { para...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1185.Day-of-the-Week/1185. Day of the Week.go
leetcode/1185.Day-of-the-Week/1185. Day of the Week.go
package leetcode import "time" func dayOfTheWeek(day int, month int, year int) string { return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.Local).Weekday().String() }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0016.3Sum-Closest/16. 3Sum Closest.go
leetcode/0016.3Sum-Closest/16. 3Sum Closest.go
package leetcode import ( "math" "sort" ) // 解法一 O(n^2) func threeSumClosest(nums []int, target int) int { n, res, diff := len(nums), 0, math.MaxInt32 if n > 2 { sort.Ints(nums) for i := 0; i < n-2; i++ { if i > 0 && nums[i] == nums[i-1] { continue } for j, k := i+1, n-1; j < k; { sum := nums...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0016.3Sum-Closest/16. 3Sum Closest_test.go
leetcode/0016.3Sum-Closest/16. 3Sum Closest_test.go
package leetcode import ( "fmt" "testing" ) type question16 struct { para16 ans16 } // para 是参数 // one 代表第一个参数 type para16 struct { a []int target int } // ans 是答案 // one 代表第一个答案 type ans16 struct { one int } func Test_Problem16(t *testing.T) { qs := []question16{ { para16{[]int{-1, 0, 1, 1, 55...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0952.Largest-Component-Size-by-Common-Factor/952. Largest Component Size by Common Factor_test.go
leetcode/0952.Largest-Component-Size-by-Common-Factor/952. Largest Component Size by Common Factor_test.go
package leetcode import ( "fmt" "testing" ) type question952 struct { para952 ans952 } // para 是参数 // one 代表第一个参数 type para952 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans952 struct { one int } func Test_Problem952(t *testing.T) { qs := []question952{ { para952{[]int{1, 2, 3, 4, 5, 6, 7, 8,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0952.Largest-Component-Size-by-Common-Factor/952. Largest Component Size by Common Factor.go
leetcode/0952.Largest-Component-Size-by-Common-Factor/952. Largest Component Size by Common Factor.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) // 解法一 并查集 UnionFind func largestComponentSize(A []int) int { maxElement, uf, countMap, res := 0, template.UnionFind{}, map[int]int{}, 1 for _, v := range A { maxElement = max(maxElement, v) } uf.Init(maxElement + 1) for _, v := range A { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0125.Valid-Palindrome/125. Valid Palindrome.go
leetcode/0125.Valid-Palindrome/125. Valid Palindrome.go
package leetcode import ( "strings" ) func isPalindrome(s string) bool { s = strings.ToLower(s) i, j := 0, len(s)-1 for i < j { for i < j && !isChar(s[i]) { i++ } for i < j && !isChar(s[j]) { j-- } if s[i] != s[j] { return false } i++ j-- } return true } // 判断 c 是否是字符或者数字 func isChar(c...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0125.Valid-Palindrome/125. Valid Palindrome_test.go
leetcode/0125.Valid-Palindrome/125. Valid Palindrome_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem125(t *testing.T) { tcs := []struct { s string ans bool }{ { "0p", false, }, { "0", true, }, { "race a car", false, }, { "A man, a plan, a canal: Panama", true, }, } fmt.Printf("----------------------...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0609.Find-Duplicate-File-in-System/609. Find Duplicate File in System_test.go
leetcode/0609.Find-Duplicate-File-in-System/609. Find Duplicate File in System_test.go
package leetcode import ( "fmt" "testing" ) type question609 struct { para609 ans609 } // para 是参数 // one 代表第一个参数 type para609 struct { paths []string } // ans 是答案 // one 代表第一个答案 type ans609 struct { one [][]string } func Test_Problem609(t *testing.T) { qs := []question609{ { para609{[]string{"root/a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0609.Find-Duplicate-File-in-System/609. Find Duplicate File in System.go
leetcode/0609.Find-Duplicate-File-in-System/609. Find Duplicate File in System.go
package leetcode import "strings" func findDuplicate(paths []string) [][]string { cache := make(map[string][]string) for _, path := range paths { parts := strings.Split(path, " ") dir := parts[0] for i := 1; i < len(parts); i++ { bracketPosition := strings.IndexByte(parts[i], '(') content := parts[i][br...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0036.Valid-Sudoku/36. Valid Sudoku_test.go
leetcode/0036.Valid-Sudoku/36. Valid Sudoku_test.go
package leetcode import ( "fmt" "testing" ) type question36 struct { para36 ans36 } // para 是参数 // one 代表第一个参数 type para36 struct { s [][]byte } // ans 是答案 // one 代表第一个答案 type ans36 struct { s bool } func Test_Problem36(t *testing.T) { qs := []question36{ { para36{[][]byte{ {'5', '3', '.', '.', '...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0036.Valid-Sudoku/36. Valid Sudoku.go
leetcode/0036.Valid-Sudoku/36. Valid Sudoku.go
package leetcode import "strconv" // 解法一 暴力遍历,时间复杂度 O(n^3) func isValidSudoku(board [][]byte) bool { // 判断行 row for i := 0; i < 9; i++ { tmp := [10]int{} for j := 0; j < 9; j++ { cellVal := board[i][j : j+1] if string(cellVal) != "." { index, _ := strconv.Atoi(string(cellVal)) if index > 9 || inde...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0032.Longest-Valid-Parentheses/32. Longest Valid Parentheses_test.go
leetcode/0032.Longest-Valid-Parentheses/32. Longest Valid Parentheses_test.go
package leetcode import ( "fmt" "testing" ) type question32 struct { para32 ans32 } // para 是参数 // one 代表第一个参数 type para32 struct { s string } // ans 是答案 // one 代表第一个答案 type ans32 struct { one int } func Test_Problem32(t *testing.T) { qs := []question32{ { para32{"(()"}, ans32{2}, }, { par...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0032.Longest-Valid-Parentheses/32. Longest Valid Parentheses.go
leetcode/0032.Longest-Valid-Parentheses/32. Longest Valid Parentheses.go
package leetcode // 解法一 栈 func longestValidParentheses(s string) int { stack, res := []int{}, 0 stack = append(stack, -1) for i := 0; i < len(s); i++ { if s[i] == '(' { stack = append(stack, i) } else { stack = stack[:len(stack)-1] if len(stack) == 0 { stack = append(stack, i) } else { res =...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false