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/0451.Sort-Characters-By-Frequency/451. Sort Characters By Frequency_test.go
leetcode/0451.Sort-Characters-By-Frequency/451. Sort Characters By Frequency_test.go
package leetcode import ( "fmt" "testing" ) type question451 struct { para451 ans451 } // para 是参数 // one 代表第一个参数 type para451 struct { one string } // ans 是答案 // one 代表第一个答案 type ans451 struct { one string } func Test_Problem451(t *testing.T) { qs := []question451{ { para451{"tree"}, ans451{"eert"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0451.Sort-Characters-By-Frequency/451. Sort Characters By Frequency.go
leetcode/0451.Sort-Characters-By-Frequency/451. Sort Characters By Frequency.go
package leetcode import ( "sort" ) func frequencySort(s string) string { if s == "" { return "" } sMap := map[byte]int{} cMap := map[int][]byte{} sb := []byte(s) for _, b := range sb { sMap[b]++ } for key, value := range sMap { cMap[value] = append(cMap[value], key) } var keys []int for k := range ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0898.Bitwise-ORs-of-Subarrays/898. Bitwise ORs of Subarrays_test.go
leetcode/0898.Bitwise-ORs-of-Subarrays/898. Bitwise ORs of Subarrays_test.go
package leetcode import ( "fmt" "testing" ) type question898 struct { para898 ans898 } // para 是参数 // one 代表第一个参数 type para898 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans898 struct { one int } func Test_Problem898(t *testing.T) { qs := []question898{ { para898{[]int{0}}, ans898{1}, }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0898.Bitwise-ORs-of-Subarrays/898. Bitwise ORs of Subarrays.go
leetcode/0898.Bitwise-ORs-of-Subarrays/898. Bitwise ORs of Subarrays.go
package leetcode // 解法一 array 优化版 func subarrayBitwiseORs(A []int) int { res, cur, isInMap := []int{}, []int{}, make(map[int]bool) cur = append(cur, 0) for _, v := range A { var cur2 []int for _, vv := range cur { tmp := v | vv if !inSlice(cur2, tmp) { cur2 = append(cur2, tmp) } } if !inSlice(c...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0739.Daily-Temperatures/739. Daily Temperatures_test.go
leetcode/0739.Daily-Temperatures/739. Daily Temperatures_test.go
package leetcode import ( "fmt" "testing" ) type question739 struct { para739 ans739 } // para 是参数 // one 代表第一个参数 type para739 struct { s []int } // ans 是答案 // one 代表第一个答案 type ans739 struct { one []int } func Test_Problem739(t *testing.T) { qs := []question739{ { para739{[]int{73, 74, 75, 71, 69, 72...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0739.Daily-Temperatures/739. Daily Temperatures.go
leetcode/0739.Daily-Temperatures/739. Daily Temperatures.go
package leetcode // 解法一 普通做法 func dailyTemperatures(T []int) []int { res, j := make([]int, len(T)), 0 for i := 0; i < len(T); i++ { for j = i + 1; j < len(T); j++ { if T[j] > T[i] { res[i] = j - i break } } } return res } // 解法二 单调栈 func dailyTemperatures1(T []int) []int { res := make([]int, le...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0984.String-Without-AAA-or-BBB/984. String Without AAA or BBB_test.go
leetcode/0984.String-Without-AAA-or-BBB/984. String Without AAA or BBB_test.go
package leetcode import ( "fmt" "testing" ) type question984 struct { para984 ans984 } // para 是参数 // one 代表第一个参数 type para984 struct { a int b int } // ans 是答案 // one 代表第一个答案 type ans984 struct { one string } func Test_Problem984(t *testing.T) { qs := []question984{ { para984{1, 2}, ans984{"abb"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0984.String-Without-AAA-or-BBB/984. String Without AAA or BBB.go
leetcode/0984.String-Without-AAA-or-BBB/984. String Without AAA or BBB.go
package leetcode func strWithout3a3b(A int, B int) string { ans, a, b := "", "a", "b" if B < A { A, B = B, A a, b = b, a } Dif := B - A if A == 1 && B == 1 { // ba ans = b + a } else if A == 1 && B < 5 { // bbabb for i := 0; i < B-2; i++ { ans = ans + b } ans = b + b + a + ans } else if (B-A)/A >...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0643.Maximum-Average-Subarray-I/643. Maximum Average Subarray I_test.go
leetcode/0643.Maximum-Average-Subarray-I/643. Maximum Average Subarray I_test.go
package leetcode import ( "fmt" "testing" ) type question643 struct { para643 ans643 } // para 是参数 // one 代表第一个参数 type para643 struct { nums []int k int } // ans 是答案 // one 代表第一个答案 type ans643 struct { one float64 } func Test_Problem643(t *testing.T) { qs := []question643{ { para643{[]int{1, 12, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0643.Maximum-Average-Subarray-I/643. Maximum Average Subarray I.go
leetcode/0643.Maximum-Average-Subarray-I/643. Maximum Average Subarray I.go
package leetcode func findMaxAverage(nums []int, k int) float64 { sum := 0 for _, v := range nums[:k] { sum += v } maxSum := sum for i := k; i < len(nums); i++ { sum = sum - nums[i-k] + nums[i] maxSum = max(maxSum, sum) } return float64(maxSum) / float64(k) } func max(a, b int) int { if a > b { return...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0732.My-Calendar-III/732. My Calendar III_test.go
leetcode/0732.My-Calendar-III/732. My Calendar III_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem732(t *testing.T) { obj := Constructor732() fmt.Printf("book = %v\n\n", obj.Book(10, 20)) // returns 1 fmt.Printf("book = %v\n\n", obj.Book(50, 60)) // returns 1 fmt.Printf("book = %v\n\n", obj.Book(10, 40)) // returns 2 fmt.Printf("book = %v\n\n", o...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0732.My-Calendar-III/732. My Calendar III.go
leetcode/0732.My-Calendar-III/732. My Calendar III.go
package leetcode // SegmentTree732 define type SegmentTree732 struct { start, end, count int left, right *SegmentTree732 } // MyCalendarThree define type MyCalendarThree struct { st *SegmentTree732 maxHeight int } // Constructor732 define func Constructor732() MyCalendarThree { st := &SegmentTree73...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0278.First-Bad-Version/278. First Bad Version.go
leetcode/0278.First-Bad-Version/278. First Bad Version.go
package leetcode import "sort" /** * Forward declaration of isBadVersion API. * @param version your guess about first bad version * @return true if current version is bad * false if current version is good * func isBadVersion(version int) bool; */ func firstBadVersion(n int) int { ret...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0278.First-Bad-Version/278. First Bad Version_test.go
leetcode/0278.First-Bad-Version/278. First Bad Version_test.go
package leetcode import ( "fmt" "testing" ) type question278 struct { para278 ans278 } // para 是参数 // one 代表第一个参数 type para278 struct { n int } // ans 是答案 // one 代表第一个答案 type ans278 struct { one int } func Test_Problem278(t *testing.T) { qs := []question278{ { para278{5}, ans278{4}, }, { pa...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0566.Reshape-the-Matrix/566. Reshape the Matrix.go
leetcode/0566.Reshape-the-Matrix/566. Reshape the Matrix.go
package leetcode func matrixReshape(nums [][]int, r int, c int) [][]int { if canReshape(nums, r, c) { return reshape(nums, r, c) } return nums } func canReshape(nums [][]int, r, c int) bool { row := len(nums) colume := len(nums[0]) if row*colume == r*c { return true } return false } func reshape(nums [][...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0566.Reshape-the-Matrix/566. Reshape the Matrix_test.go
leetcode/0566.Reshape-the-Matrix/566. Reshape the Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question566 struct { para566 ans566 } // para 是参数 // one 代表第一个参数 type para566 struct { nums [][]int r int c int } // ans 是答案 // one 代表第一个答案 type ans566 struct { one [][]int } func Test_Problem566(t *testing.T) { qs := []question566{ { para566{[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0781.Rabbits-in-Forest/781. Rabbits in Forest_test.go
leetcode/0781.Rabbits-in-Forest/781. Rabbits in Forest_test.go
package leetcode import ( "fmt" "testing" ) type question781 struct { para781 ans781 } // para 是参数 // one 代表第一个参数 type para781 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans781 struct { one int } func Test_Problem781(t *testing.T) { qs := []question781{ { para781{[]int{1, 1, 2}}, ans781{5}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0781.Rabbits-in-Forest/781. Rabbits in Forest.go
leetcode/0781.Rabbits-in-Forest/781. Rabbits in Forest.go
package leetcode func numRabbits(ans []int) int { total, m := 0, make(map[int]int) for _, v := range ans { if m[v] == 0 { m[v] += v total += v + 1 } else { m[v]-- } } return total }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0567.Permutation-in-String/567. Permutation in String.go
leetcode/0567.Permutation-in-String/567. Permutation in String.go
package leetcode func checkInclusion(s1 string, s2 string) bool { var freq [256]int if len(s2) == 0 || len(s2) < len(s1) { return false } for i := 0; i < len(s1); i++ { freq[s1[i]-'a']++ } left, right, count := 0, 0, len(s1) for right < len(s2) { if freq[s2[right]-'a'] >= 1 { count-- } freq[s2[rig...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0567.Permutation-in-String/567. Permutation in String_test.go
leetcode/0567.Permutation-in-String/567. Permutation in String_test.go
package leetcode import ( "fmt" "testing" ) type question567 struct { para567 ans567 } // para 是参数 // one 代表第一个参数 type para567 struct { s string p string } // ans 是答案 // one 代表第一个答案 type ans567 struct { one bool } func Test_Problem567(t *testing.T) { qs := []question567{ { para567{"ab", "abab"}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0658.Find-K-Closest-Elements/658. Find K Closest Elements.go
leetcode/0658.Find-K-Closest-Elements/658. Find K Closest Elements.go
package leetcode import "sort" // 解法一 库函数二分搜索 func findClosestElements(arr []int, k int, x int) []int { return arr[sort.Search(len(arr)-k, func(i int) bool { return x-arr[i] <= arr[i+k]-x }):][:k] } // 解法二 手撸二分搜索 func findClosestElements1(arr []int, k int, x int) []int { low, high := 0, len(arr)-k for low < high ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0658.Find-K-Closest-Elements/658. Find K Closest Elements_test.go
leetcode/0658.Find-K-Closest-Elements/658. Find K Closest Elements_test.go
package leetcode import ( "fmt" "testing" ) type question658 struct { para658 ans658 } // para 是参数 // one 代表第一个参数 type para658 struct { arr []int k int x int } // ans 是答案 // one 代表第一个答案 type ans658 struct { one []int } func Test_Problem658(t *testing.T) { qs := []question658{ { para658{[]int{1,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0438.Find-All-Anagrams-in-a-String/438. Find All Anagrams in a String.go
leetcode/0438.Find-All-Anagrams-in-a-String/438. Find All Anagrams in a String.go
package leetcode func findAnagrams(s string, p string) []int { var freq [256]int result := []int{} if len(s) == 0 || len(s) < len(p) { return result } for i := 0; i < len(p); i++ { freq[p[i]-'a']++ } left, right, count := 0, 0, len(p) for right < len(s) { if freq[s[right]-'a'] >= 1 { count-- } fr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0438.Find-All-Anagrams-in-a-String/438. Find All Anagrams in a String_test.go
leetcode/0438.Find-All-Anagrams-in-a-String/438. Find All Anagrams in a String_test.go
package leetcode import ( "fmt" "testing" ) type question438 struct { para438 ans438 } // para 是参数 // one 代表第一个参数 type para438 struct { s string p string } // ans 是答案 // one 代表第一个答案 type ans438 struct { one []int } func Test_Problem438(t *testing.T) { qs := []question438{ { para438{"abab", "ab"}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0135.Candy/135. Candy.go
leetcode/0135.Candy/135. Candy.go
package leetcode func candy(ratings []int) int { candies := make([]int, len(ratings)) for i := 1; i < len(ratings); i++ { if ratings[i] > ratings[i-1] { candies[i] += candies[i-1] + 1 } } for i := len(ratings) - 2; i >= 0; i-- { if ratings[i] > ratings[i+1] && candies[i] <= candies[i+1] { candies[i] = ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0135.Candy/135. Candy_test.go
leetcode/0135.Candy/135. Candy_test.go
package leetcode import ( "fmt" "testing" ) type question135 struct { para135 ans135 } // para 是参数 // one 代表第一个参数 type para135 struct { ratings []int } // ans 是答案 // one 代表第一个答案 type ans135 struct { one int } func Test_Problem135(t *testing.T) { qs := []question135{ { para135{[]int{1, 0, 2}}, ans1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings/1111. Maximum Nesting Depth of Two Valid Parentheses Strings.go
leetcode/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings/1111. Maximum Nesting Depth of Two Valid Parentheses Strings.go
package leetcode // 解法一 二分思想 func maxDepthAfterSplit(seq string) []int { stack, maxDepth, res := 0, 0, []int{} for _, v := range seq { if v == '(' { stack++ maxDepth = max(stack, maxDepth) } else { stack-- } } stack = 0 for i := 0; i < len(seq); i++ { if seq[i] == '(' { stack++ if stack <= ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings/1111. Maximum Nesting Depth of Two Valid Parentheses Strings_test.go
leetcode/1111.Maximum-Nesting-Depth-of-Two-Valid-Parentheses-Strings/1111. Maximum Nesting Depth of Two Valid Parentheses Strings_test.go
package leetcode import ( "fmt" "testing" ) type question1111 struct { para1111 ans1111 } // para 是参数 // one 代表第一个参数 type para1111 struct { one string } // ans 是答案 // one 代表第一个答案 type ans1111 struct { one []int } func Test_Problem1111(t *testing.T) { qs := []question1111{ { para1111{"(()())"}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1446.Consecutive-Characters/1446.Consecutive Characters_test.go
leetcode/1446.Consecutive-Characters/1446.Consecutive Characters_test.go
package leetcode import ( "fmt" "testing" ) type question1446 struct { para1446 ans1446 } // para 是参数 type para1446 struct { s string } // ans 是答案 type ans1446 struct { ans int } func Test_Problem1446(t *testing.T) { qs := []question1446{ { para1446{"leetcode"}, ans1446{2}, }, { para1446{"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1446.Consecutive-Characters/1446.Consecutive Characters.go
leetcode/1446.Consecutive-Characters/1446.Consecutive Characters.go
package leetcode func maxPower(s string) int { cur, cnt, ans := s[0], 1, 1 for i := 1; i < len(s); i++ { if cur == s[i] { cnt++ } else { if cnt > ans { ans = cnt } cur = s[i] cnt = 1 } } if cnt > ans { ans = cnt } return ans }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0257.Binary-Tree-Paths/257. Binary Tree Paths_test.go
leetcode/0257.Binary-Tree-Paths/257. Binary Tree Paths_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question257 struct { para257 ans257 } // para 是参数 // one 代表第一个参数 type para257 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans257 struct { one []string } func Test_Problem257(t *testing.T) { qs := []quest...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0257.Binary-Tree-Paths/257. Binary Tree Paths.go
leetcode/0257.Binary-Tree-Paths/257. Binary Tree Paths.go
package leetcode import ( "strconv" "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 binaryTreePaths(root *TreeNode) [...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0110.Balanced-Binary-Tree/110. Balanced Binary Tree.go
leetcode/0110.Balanced-Binary-Tree/110. Balanced 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 isBalanced(root *TreeNode) bool { if root ==...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0110.Balanced-Binary-Tree/110. Balanced Binary Tree_test.go
leetcode/0110.Balanced-Binary-Tree/110. Balanced Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question110 struct { para110 ans110 } // para 是参数 // one 代表第一个参数 type para110 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans110 struct { one bool } func Test_Problem110(t *testing.T) { qs := []question1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0126.Word-Ladder-II/126. Word Ladder II.go
leetcode/0126.Word-Ladder-II/126. Word Ladder II.go
package leetcode func findLadders(beginWord string, endWord string, wordList []string) [][]string { result, wordMap := make([][]string, 0), make(map[string]bool) for _, w := range wordList { wordMap[w] = true } if !wordMap[endWord] { return result } // create a queue, track the path queue := make([][]string...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0126.Word-Ladder-II/126. Word Ladder II_test.go
leetcode/0126.Word-Ladder-II/126. Word Ladder II_test.go
package leetcode import ( "fmt" "testing" ) type question126 struct { para126 ans126 } // para 是参数 // one 代表第一个参数 type para126 struct { b string e string w []string } // ans 是答案 // one 代表第一个答案 type ans126 struct { one [][]string } func Test_Problem126(t *testing.T) { qs := []question126{ { para126{"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1078.Occurrences-After-Bigram/1078. Occurrences After Bigram_test.go
leetcode/1078.Occurrences-After-Bigram/1078. Occurrences After Bigram_test.go
package leetcode import ( "fmt" "testing" ) type question1078 struct { para1078 ans1078 } // para 是参数 // one 代表第一个参数 type para1078 struct { t string f string s string } // ans 是答案 // one 代表第一个答案 type ans1078 struct { one []string } func Test_Problem1078(t *testing.T) { qs := []question1078{ { para1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1078.Occurrences-After-Bigram/1078. Occurrences After Bigram.go
leetcode/1078.Occurrences-After-Bigram/1078. Occurrences After Bigram.go
package leetcode import "strings" func findOcurrences(text string, first string, second string) []string { var res []string words := strings.Split(text, " ") if len(words) < 3 { return []string{} } for i := 2; i < len(words); i++ { if words[i-2] == first && words[i-1] == second { res = append(res, words[i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0284.Peeking-Iterator/284. Peeking Iterator.go
leetcode/0284.Peeking-Iterator/284. Peeking Iterator.go
package leetcode //Below is the interface for Iterator, which is already defined for you. type Iterator struct { } func (this *Iterator) hasNext() bool { // Returns true if the iteration has more elements. return true } func (this *Iterator) next() int { // Returns the next element in the iteration. return 0 } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0284.Peeking-Iterator/284. Peeking Iterator_test.go
leetcode/0284.Peeking-Iterator/284. Peeking Iterator_test.go
package leetcode import ( "testing" ) func Test_Problem284(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/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/1217. Minimum Cost to Move Chips to The Same Position_test.go
leetcode/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/1217. Minimum Cost to Move Chips to The Same Position_test.go
package leetcode import ( "fmt" "testing" ) type question1217 struct { para1217 ans1217 } // para 是参数 // one 代表第一个参数 type para1217 struct { arr []int } // ans 是答案 // one 代表第一个答案 type ans1217 struct { one int } func Test_Problem1217(t *testing.T) { qs := []question1217{ { para1217{[]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/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/1217. Minimum Cost to Move Chips to The Same Position.go
leetcode/1217.Minimum-Cost-to-Move-Chips-to-The-Same-Position/1217. Minimum Cost to Move Chips to The Same Position.go
package leetcode func minCostToMoveChips(chips []int) int { odd, even := 0, 0 for _, c := range chips { if c%2 == 0 { even++ } else { odd++ } } return min(odd, even) } func min(a int, b int) int { if a > b { return b } return a }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal/105. Construct Binary Tree from Preorder and Inorder Traversal.go
leetcode/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal/105. Construct Binary Tree from Preorder and Inorder Traversal.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 * } */ // 解法一, 直接传入需要的 slice 范围作为输入, 可以避免申请对应 inorder 索引的...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal/105. Construct Binary Tree from Preorder and Inorder Traversal_test.go
leetcode/0105.Construct-Binary-Tree-from-Preorder-and-Inorder-Traversal/105. Construct Binary Tree from Preorder and Inorder Traversal_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question105 struct { para105 ans105 } // para 是参数 // one 代表第一个参数 type para105 struct { preorder []int inorder []int } // ans 是答案 // one 代表第一个答案 type ans105 struct { one []int } func Test_Problem105(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/0357.Count-Numbers-with-Unique-Digits/357. Count Numbers with Unique Digits.go
leetcode/0357.Count-Numbers-with-Unique-Digits/357. Count Numbers with Unique Digits.go
package leetcode // 暴力打表法 func countNumbersWithUniqueDigits1(n int) int { res := []int{1, 10, 91, 739, 5275, 32491, 168571, 712891, 2345851, 5611771, 8877691} if n >= 10 { return res[10] } return res[n] } // 打表方法 func countNumbersWithUniqueDigits(n int) int { if n == 0 { return 1 } res, uniqueDigits, avail...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0357.Count-Numbers-with-Unique-Digits/357. Count Numbers with Unique Digits_test.go
leetcode/0357.Count-Numbers-with-Unique-Digits/357. Count Numbers with Unique Digits_test.go
package leetcode import ( "fmt" "testing" ) type question357 struct { para357 ans357 } // para 是参数 // one 代表第一个参数 type para357 struct { one int } // ans 是答案 // one 代表第一个答案 type ans357 struct { one int } func Test_Problem357(t *testing.T) { qs := []question357{ { para357{1}, ans357{10}, }, { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0287.Find-the-Duplicate-Number/287. Find the Duplicate Number.go
leetcode/0287.Find-the-Duplicate-Number/287. Find the Duplicate Number.go
package leetcode import "sort" // 解法一 快慢指针 func findDuplicate(nums []int) int { slow := nums[0] fast := nums[nums[0]] for fast != slow { slow = nums[slow] fast = nums[nums[fast]] } walker := 0 for walker != slow { walker = nums[walker] slow = nums[slow] } return walker } // 解法二 二分搜索 func findDuplicat...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0287.Find-the-Duplicate-Number/287. Find the Duplicate Number_test.go
leetcode/0287.Find-the-Duplicate-Number/287. Find the Duplicate Number_test.go
package leetcode import ( "fmt" "testing" ) type question287 struct { para287 ans287 } // para 是参数 // one 代表第一个参数 type para287 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans287 struct { one int } func Test_Problem287(t *testing.T) { qs := []question287{ { para287{[]int{1, 3, 4, 2, 2}}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0953.Verifying-an-Alien-Dictionary/953. Verifying an Alien Dictionary_test.go
leetcode/0953.Verifying-an-Alien-Dictionary/953. Verifying an Alien Dictionary_test.go
package leetcode import ( "fmt" "testing" ) type question953 struct { para953 ans953 } // para 是参数 // one 代表第一个参数 type para953 struct { one []string two string } // ans 是答案 // one 代表第一个答案 type ans953 struct { one bool } func Test_Problem953(t *testing.T) { qs := []question953{ { para953{[]string{"hel...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0953.Verifying-an-Alien-Dictionary/953. Verifying an Alien Dictionary.go
leetcode/0953.Verifying-an-Alien-Dictionary/953. Verifying an Alien Dictionary.go
package leetcode func isAlienSorted(words []string, order string) bool { if len(words) < 2 { return true } hash := make(map[byte]int) for i := 0; i < len(order); i++ { hash[order[i]] = i } for i := 0; i < len(words)-1; i++ { pointer, word, wordplus := 0, words[i], words[i+1] for pointer < len(word) && po...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0205.Isomorphic-Strings/205. Isomorphic Strings_test.go
leetcode/0205.Isomorphic-Strings/205. Isomorphic Strings_test.go
package leetcode import ( "fmt" "testing" ) type question205 struct { para205 ans205 } // para 是参数 // one 代表第一个参数 type para205 struct { one string two string } // ans 是答案 // one 代表第一个答案 type ans205 struct { one bool } func Test_Problem205(t *testing.T) { qs := []question205{ { para205{"egg", "add"},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0205.Isomorphic-Strings/205. Isomorphic Strings.go
leetcode/0205.Isomorphic-Strings/205. Isomorphic Strings.go
package leetcode func isIsomorphic(s string, t string) bool { strList := []byte(t) patternByte := []byte(s) if (s == "" && t != "") || (len(patternByte) != len(strList)) { return false } pMap := map[byte]byte{} sMap := map[byte]byte{} for index, b := range patternByte { if _, ok := pMap[b]; !ok { if _, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0083.Remove-Duplicates-from-Sorted-List/83. Remove Duplicates from Sorted List.go
leetcode/0083.Remove-Duplicates-from-Sorted-List/83. Remove Duplicates from Sorted 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 deleteDuplicates(head *ListNode) *ListNode { cur := head if head =...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0083.Remove-Duplicates-from-Sorted-List/83. Remove Duplicates from Sorted List_test.go
leetcode/0083.Remove-Duplicates-from-Sorted-List/83. Remove Duplicates from Sorted List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question83 struct { para83 ans83 } // para 是参数 // one 代表第一个参数 type para83 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans83 struct { one []int } func Test_Problem83(t *testing.T) { qs := []question83{ ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0230.Kth-Smallest-Element-in-a-BST/230. Kth Smallest Element in a BST_test.go
leetcode/0230.Kth-Smallest-Element-in-a-BST/230. Kth Smallest Element in a BST_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question230 struct { para230 ans230 } // para 是参数 // one 代表第一个参数 type para230 struct { one []int k int } // ans 是答案 // one 代表第一个答案 type ans230 struct { one int } func Test_Problem230(t *testing.T) { qs := []q...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0230.Kth-Smallest-Element-in-a-BST/230. Kth Smallest Element in a BST.go
leetcode/0230.Kth-Smallest-Element-in-a-BST/230. Kth Smallest Element in a BST.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func kthSmallest(root *TreeNode, k int) int { res...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0022.Generate-Parentheses/22. Generate Parentheses_test.go
leetcode/0022.Generate-Parentheses/22. Generate Parentheses_test.go
package leetcode import ( "fmt" "testing" ) type question22 struct { para22 ans22 } // para 是参数 // one 代表第一个参数 type para22 struct { one int } // ans 是答案 // one 代表第一个答案 type ans22 struct { one []string } func Test_Problem22(t *testing.T) { qs := []question22{ { para22{3}, ans22{[]string{ "((())...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0022.Generate-Parentheses/22. Generate Parentheses.go
leetcode/0022.Generate-Parentheses/22. Generate Parentheses.go
package leetcode func generateParenthesis(n int) []string { if n == 0 { return []string{} } res := []string{} findGenerateParenthesis(n, n, "", &res) return res } func findGenerateParenthesis(lindex, rindex int, str string, res *[]string) { if lindex == 0 && rindex == 0 { *res = append(*res, str) return ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0885.Spiral-Matrix-III/885. Spiral Matrix III_test.go
leetcode/0885.Spiral-Matrix-III/885. Spiral Matrix III_test.go
package leetcode import ( "fmt" "testing" ) type question885 struct { para885 ans885 } // para 是参数 // one 代表第一个参数 type para885 struct { R int C int r0 int c0 int } // ans 是答案 // one 代表第一个答案 type ans885 struct { one [][]int } func Test_Problem885(t *testing.T) { qs := []question885{ { para885{1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0885.Spiral-Matrix-III/885. Spiral Matrix III.go
leetcode/0885.Spiral-Matrix-III/885. Spiral Matrix III.go
package leetcode func spiralMatrixIII(R int, C int, r0 int, c0 int) [][]int { res, round, spDir := [][]int{}, 0, [][]int{ {0, 1}, // 朝右 {1, 0}, // 朝下 {0, -1}, // 朝左 {-1, 0}, // 朝上 } res = append(res, []int{r0, c0}) for i := 0; len(res) < R*C; i++ { for j := 0; j < i/2+1; j++ { r0 += spDir[round%4][0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0802.Find-Eventual-Safe-States/802. Find Eventual Safe States_test.go
leetcode/0802.Find-Eventual-Safe-States/802. Find Eventual Safe States_test.go
package leetcode import ( "fmt" "testing" ) type question802 struct { para802 ans802 } // para 是参数 // one 代表第一个参数 type para802 struct { graph [][]int } // ans 是答案 // one 代表第一个答案 type ans802 struct { one []int } func Test_Problem802(t *testing.T) { qs := []question802{ { para802{[][]int{{1, 2}, {2, 3}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0802.Find-Eventual-Safe-States/802. Find Eventual Safe States.go
leetcode/0802.Find-Eventual-Safe-States/802. Find Eventual Safe States.go
package leetcode func eventualSafeNodes(graph [][]int) []int { res, color := []int{}, make([]int, len(graph)) for i := range graph { if dfsEventualSafeNodes(graph, i, color) { res = append(res, i) } } return res } // colors: WHITE 0, GRAY 1, BLACK 2; func dfsEventualSafeNodes(graph [][]int, idx int, color ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0628.Maximum-Product-of-Three-Numbers/628. Maximum Product of Three Numbers.go
leetcode/0628.Maximum-Product-of-Three-Numbers/628. Maximum Product of Three Numbers.go
package leetcode import ( "math" "sort" ) // 解法一 排序,时间复杂度 O(n log n) func maximumProduct(nums []int) int { if len(nums) == 0 { return 0 } res := 1 if len(nums) <= 3 { for i := 0; i < len(nums); i++ { res = res * nums[i] } return res } sort.Ints(nums) if nums[len(nums)-1] <= 0 { return 0 } retu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0628.Maximum-Product-of-Three-Numbers/628. Maximum Product of Three Numbers_test.go
leetcode/0628.Maximum-Product-of-Three-Numbers/628. Maximum Product of Three Numbers_test.go
package leetcode import ( "fmt" "testing" ) type question628 struct { para628 ans628 } // para 是参数 // one 代表第一个参数 type para628 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans628 struct { one int } func Test_Problem628(t *testing.T) { qs := []question628{ { para628{[]int{3, -1, 4}}, ans628{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0525.Contiguous-Array/525. Contiguous Array.go
leetcode/0525.Contiguous-Array/525. Contiguous Array.go
package leetcode func findMaxLength(nums []int) int { dict := map[int]int{} dict[0] = -1 count, res := 0, 0 for i := 0; i < len(nums); i++ { if nums[i] == 0 { count-- } else { count++ } if idx, ok := dict[count]; ok { res = max(res, i-idx) } else { dict[count] = i } } return res } func m...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0525.Contiguous-Array/525. Contiguous Array_test.go
leetcode/0525.Contiguous-Array/525. Contiguous Array_test.go
package leetcode import ( "fmt" "testing" ) type question525 struct { para525 ans525 } // para 是参数 // one 代表第一个参数 type para525 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans525 struct { one int } func Test_Problem525(t *testing.T) { qs := []question525{ { para525{[]int{0, 1}}, ans525{2},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0134.Gas-Station/Gas.go
leetcode/0134.Gas-Station/Gas.go
package leetcode func canCompleteCircuit(gas []int, cost []int) int { totalGas := 0 totalCost := 0 currGas := 0 start := 0 for i := 0; i < len(gas); i++ { totalGas += gas[i] totalCost += cost[i] currGas += gas[i] - cost[i] if currGas < 0 { start = i + 1 currGas = 0 } } if totalGas < totalCost...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0134.Gas-Station/Gas_test.go
leetcode/0134.Gas-Station/Gas_test.go
package leetcode import ( "fmt" "testing" ) type question134 struct { para134 ans134 } // para 是参数 // one 代表第一个参数 type para134 struct { one []int two []int } // ans 是答案 // one 代表第一个答案 type ans134 struct { one int } func Test_Problem134(t *testing.T) { qs := []question134{ { para134{[]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/0143.Reorder-List/143. Reorder List_test.go
leetcode/0143.Reorder-List/143. Reorder List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question143 struct { para143 ans143 } // para 是参数 // one 代表第一个参数 type para143 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans143 struct { one []int } func Test_Problem143(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/0143.Reorder-List/143. Reorder List.go
leetcode/0143.Reorder-List/143. Reorder 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 reorderList(head *ListNode) *ListNode { if head == nil |...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0220.Contains-Duplicate-III/220. Contains Duplicate III_test.go
leetcode/0220.Contains-Duplicate-III/220. Contains Duplicate III_test.go
package leetcode import ( "fmt" "testing" ) type question220 struct { para220 ans220 } // para 是参数 // one 代表第一个参数 type para220 struct { one []int k int t int } // ans 是答案 // one 代表第一个答案 type ans220 struct { one bool } func Test_Problem220(t *testing.T) { qs := []question220{ { para220{[]int{7, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0220.Contains-Duplicate-III/220. Contains Duplicate III.go
leetcode/0220.Contains-Duplicate-III/220. Contains Duplicate III.go
package leetcode // 解法一 桶排序 func containsNearbyAlmostDuplicate(nums []int, k int, t int) bool { if k <= 0 || t < 0 || len(nums) < 2 { return false } buckets := map[int]int{} for i := 0; i < len(nums); i++ { // Get the ID of the bucket from element value nums[i] and bucket width t + 1 key := nums[i] / (t + 1)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2164.Sort-Even-and-Odd-Indices-Independently/2164. Sort Even and Odd Indices Independently_test.go
leetcode/2164.Sort-Even-and-Odd-Indices-Independently/2164. Sort Even and Odd Indices Independently_test.go
package leetcode import ( "fmt" "testing" ) type question2164 struct { para2164 ans2164 } // para 是参数 // one 代表第一个参数 type para2164 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans2164 struct { one []int } func Test_Problem1(t *testing.T) { qs := []question2164{ { para2164{[]int{4, 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/2164.Sort-Even-and-Odd-Indices-Independently/2164. Sort Even and Odd Indices Independently.go
leetcode/2164.Sort-Even-and-Odd-Indices-Independently/2164. Sort Even and Odd Indices Independently.go
package leetcode import ( "sort" ) func sortEvenOdd(nums []int) []int { odd, even, res := []int{}, []int{}, []int{} for index, v := range nums { if index%2 == 0 { even = append(even, v) } else { odd = append(odd, v) } } sort.Ints(even) sort.Sort(sort.Reverse(sort.IntSlice(odd))) indexO, indexE := ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0088.Merge-Sorted-Array/88. Merge Sorted Array.go
leetcode/0088.Merge-Sorted-Array/88. Merge Sorted Array.go
package leetcode func merge(nums1 []int, m int, nums2 []int, n int) { for p := m + n; m > 0 && n > 0; p-- { if nums1[m-1] <= nums2[n-1] { nums1[p-1] = nums2[n-1] n-- } else { nums1[p-1] = nums1[m-1] m-- } } for ; n > 0; n-- { nums1[n-1] = nums2[n-1] } }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0088.Merge-Sorted-Array/88. Merge Sorted Array_test.go
leetcode/0088.Merge-Sorted-Array/88. Merge Sorted Array_test.go
package leetcode import ( "fmt" "testing" ) type question88 struct { para88 ans88 } // para 是参数 // one 代表第一个参数 type para88 struct { one []int m int two []int n int } // ans 是答案 // one 代表第一个答案 type ans88 struct { one []int } func Test_Problem88(t *testing.T) { qs := []question88{ { para88{[]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1296.Divide-Array-in-Sets-of-K-Consecutive-Numbers/1296.Divide Array in Sets of K Consecutive Numbers_test.go
leetcode/1296.Divide-Array-in-Sets-of-K-Consecutive-Numbers/1296.Divide Array in Sets of K Consecutive Numbers_test.go
package leetcode import ( "fmt" "testing" ) type question1296 struct { para1296 ans1296 } // para 是参数 type para1296 struct { nums []int k int } // ans 是答案 type ans1296 struct { ans bool } func Test_Problem1296(t *testing.T) { qs := []question1296{ { para1296{[]int{1, 2, 3, 3, 4, 4, 5, 6}, 4}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1296.Divide-Array-in-Sets-of-K-Consecutive-Numbers/1296.Divide Array in Sets of K Consecutive Numbers.go
leetcode/1296.Divide-Array-in-Sets-of-K-Consecutive-Numbers/1296.Divide Array in Sets of K Consecutive Numbers.go
package leetcode import "sort" func isPossibleDivide(nums []int, k int) bool { mp := make(map[int]int) for _, v := range nums { mp[v] += 1 } sort.Ints(nums) for _, num := range nums { if mp[num] == 0 { continue } for diff := 0; diff < k; diff++ { if mp[num+diff] == 0 { return false } mp[n...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1748.Sum-of-Unique-Elements/1748. Sum of Unique Elements.go
leetcode/1748.Sum-of-Unique-Elements/1748. Sum of Unique Elements.go
package leetcode func sumOfUnique(nums []int) int { freq, res := make(map[int]int), 0 for _, v := range nums { if _, ok := freq[v]; !ok { freq[v] = 0 } freq[v]++ } for k, v := range freq { if v == 1 { res += k } } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1748.Sum-of-Unique-Elements/1748. Sum of Unique Elements_test.go
leetcode/1748.Sum-of-Unique-Elements/1748. Sum of Unique Elements_test.go
package leetcode import ( "fmt" "testing" ) type question1748 struct { para1748 ans1748 } // para 是参数 // one 代表第一个参数 type para1748 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1748 struct { one int } func Test_Problem1748(t *testing.T) { qs := []question1748{ { para1748{[]int{1, 2, 3, 2}},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0040.Combination-Sum-II/40. Combination Sum II_test.go
leetcode/0040.Combination-Sum-II/40. Combination Sum II_test.go
package leetcode import ( "fmt" "testing" ) type question40 struct { para40 ans40 } // para 是参数 // one 代表第一个参数 type para40 struct { n []int k int } // ans 是答案 // one 代表第一个答案 type ans40 struct { one [][]int } func Test_Problem40(t *testing.T) { qs := []question40{ { para40{[]int{10, 1, 2, 7, 6, 1, 5}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0040.Combination-Sum-II/40. Combination Sum II.go
leetcode/0040.Combination-Sum-II/40. Combination Sum II.go
package leetcode import ( "sort" ) func combinationSum2(candidates []int, target int) [][]int { if len(candidates) == 0 { return [][]int{} } c, res := []int{}, [][]int{} sort.Ints(candidates) // 这里是去重的关键逻辑 findcombinationSum2(candidates, target, 0, c, &res) return res } func findcombinationSum2(nums []int, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0429.N-ary-Tree-Level-Order-Traversal/429. N-ary Tree Level Order Traversal.go
leetcode/0429.N-ary-Tree-Level-Order-Traversal/429. N-ary Tree Level Order Traversal.go
package leetcode /** * Definition for a Node. * type Node struct { * Val int * Children []*Node * } */ type Node struct { Val int Children []*Node } func levelOrder(root *Node) [][]int { var res [][]int var temp []int if root == nil { return res } queue := []*Node{root, nil} for len(queu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0429.N-ary-Tree-Level-Order-Traversal/429. N-ary Tree Level Order Traversal_test.go
leetcode/0429.N-ary-Tree-Level-Order-Traversal/429. N-ary Tree Level Order Traversal_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem429(t *testing.T) { fmt.Printf("success\n") }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0513.Find-Bottom-Left-Tree-Value/513. Find Bottom Left Tree Value_test.go
leetcode/0513.Find-Bottom-Left-Tree-Value/513. Find Bottom Left Tree Value_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question513 struct { para513 ans513 } // para 是参数 // one 代表第一个参数 type para513 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans513 struct { one int } func Test_Problem513(t *testing.T) { qs := []question51...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0513.Find-Bottom-Left-Tree-Value/513. Find Bottom Left Tree Value.go
leetcode/0513.Find-Bottom-Left-Tree-Value/513. Find Bottom Left Tree Value.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 * } */ // 解法一 DFS func findBottomLeftValue(root *TreeNode...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0991.Broken-Calculator/991. Broken Calculator.go
leetcode/0991.Broken-Calculator/991. Broken Calculator.go
package leetcode func brokenCalc(X int, Y int) int { res := 0 for Y > X { res++ if Y&1 == 1 { Y++ } else { Y /= 2 } } return res + X - Y }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0991.Broken-Calculator/991. Broken Calculator_test.go
leetcode/0991.Broken-Calculator/991. Broken Calculator_test.go
package leetcode import ( "fmt" "testing" ) type question991 struct { para991 ans991 } // para 是参数 // one 代表第一个参数 type para991 struct { X int Y int } // ans 是答案 // one 代表第一个答案 type ans991 struct { one int } func Test_Problem991(t *testing.T) { qs := []question991{ { para991{2, 3}, ans991{2}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions_test.go
leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions_test.go
package leetcode import ( "fmt" "testing" ) type question1649 struct { para1649 ans1649 } // para 是参数 // one 代表第一个参数 type para1649 struct { instructions []int } // ans 是答案 // one 代表第一个答案 type ans1649 struct { one int } func Test_Problem1649(t *testing.T) { qs := []question1649{ { para1649{[]int{1, 5,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions.go
leetcode/1649.Create-Sorted-Array-through-Instructions/1649. Create Sorted Array through Instructions.go
package leetcode import ( "sort" "github.com/halfrost/LeetCode-Go/template" ) // 解法一 树状数组 Binary Indexed Tree func createSortedArray(instructions []int) int { bit, res := template.BinaryIndexedTree{}, 0 bit.Init(100001) for i, v := range instructions { less := bit.Query(v - 1) greater := i - bit.Query(v) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0329.Longest-Increasing-Path-in-a-Matrix/329. Longest Increasing Path in a Matrix.go
leetcode/0329.Longest-Increasing-Path-in-a-Matrix/329. Longest Increasing Path in a Matrix.go
package leetcode import ( "math" ) var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } func longestIncreasingPath(matrix [][]int) int { cache, res := make([][]int, len(matrix)), 0 for i := 0; i < len(cache); i++ { cache[i] = make([]int, len(matrix[0])) } for i, v := range matrix { for j := range v { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0329.Longest-Increasing-Path-in-a-Matrix/329. Longest Increasing Path in a Matrix_test.go
leetcode/0329.Longest-Increasing-Path-in-a-Matrix/329. Longest Increasing Path in a Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question329 struct { para329 ans329 } // para 是参数 // one 代表第一个参数 type para329 struct { matrix [][]int } // ans 是答案 // one 代表第一个答案 type ans329 struct { one int } func Test_Problem329(t *testing.T) { qs := []question329{ { para329{[][]int{{1}}}, ans32...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings.go
leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings.go
package leetcode // 解法一 打表 func countVowelStrings(n int) int { res := []int{1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 8855, 10626, 12650, 14950, 17550, 20475, 23751, 27405, 31465, 35960, 40920, 46376, 52360, 58905, 66045, 73815, 82251, 91390, 101270, 111930, 1234...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings_test.go
leetcode/1641.Count-Sorted-Vowel-Strings/1641. Count Sorted Vowel Strings_test.go
package leetcode import ( "fmt" "testing" ) type question1641 struct { para1641 ans1641 } // para 是参数 // one 代表第一个参数 type para1641 struct { n int } // ans 是答案 // one 代表第一个答案 type ans1641 struct { one int } func Test_Problem1641(t *testing.T) { qs := []question1641{ { para1641{1}, ans1641{5}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String_test.go
leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String_test.go
package leetcode import ( "fmt" "testing" ) type question1573 struct { para1573 ans1573 } // para 是参数 // one 代表第一个参数 type para1573 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1573 struct { one int } func Test_Problem1573(t *testing.T) { qs := []question1573{ { para1573{"10101"}, ans1573{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String.go
leetcode/1573.Number-of-Ways-to-Split-a-String/1573. Number of Ways to Split a String.go
package leetcode func numWays(s string) int { ones := 0 for _, c := range s { if c == '1' { ones++ } } if ones%3 != 0 { return 0 } if ones == 0 { return (len(s) - 1) * (len(s) - 2) / 2 % 1000000007 } N, a, b, c, d, count := ones/3, 0, 0, 0, 0, 0 for i, letter := range s { if letter == '0' { co...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0326.Power-of-Three/326. Power of Three_test.go
leetcode/0326.Power-of-Three/326. Power of Three_test.go
package leetcode import ( "fmt" "testing" ) type question326 struct { para326 ans326 } // para 是参数 // one 代表第一个参数 type para326 struct { one int } // ans 是答案 // one 代表第一个答案 type ans326 struct { one bool } func Test_Problem326(t *testing.T) { qs := []question326{ { para326{27}, ans326{true}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0326.Power-of-Three/326. Power of Three.go
leetcode/0326.Power-of-Three/326. Power of Three.go
package leetcode // 解法一 数论 func isPowerOfThree(n int) bool { // 1162261467 is 3^19, 3^20 is bigger than int return n > 0 && (1162261467%n == 0) } // 解法二 打表法 func isPowerOfThree1(n int) bool { // 1162261467 is 3^19, 3^20 is bigger than int allPowerOfThreeMap := map[int]int{1: 1, 3: 3, 9: 9, 27: 27, 81: 81, 243: ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number.go
leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number.go
package leetcode import ( "strings" ) func reformatNumber(number string) string { parts, nums := []string{}, []rune{} for _, r := range number { if r != '-' && r != ' ' { nums = append(nums, r) } } threeDigits, twoDigits := len(nums)/3, 0 switch len(nums) % 3 { case 1: threeDigits-- twoDigits = 2 c...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number_test.go
leetcode/1694.Reformat-Phone-Number/1694. Reformat Phone Number_test.go
package leetcode import ( "fmt" "testing" ) type question1694 struct { para1694 ans1694 } // para 是参数 // one 代表第一个参数 type para1694 struct { number string } // ans 是答案 // one 代表第一个答案 type ans1694 struct { one string } func Test_Problem1694(t *testing.T) { qs := []question1694{ { para1694{"1-23-45 6"},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false