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/0825.Friends-Of-Appropriate-Ages/825. Friends Of Appropriate Ages_test.go
leetcode/0825.Friends-Of-Appropriate-Ages/825. Friends Of Appropriate Ages_test.go
package leetcocde import ( "fmt" "testing" ) type question825 struct { para825 ans825 } // para 是参数 // one 代表第一个参数 type para825 struct { ages []int } // ans 是答案 // one 代表第一个答案 type ans825 struct { one int } func Test_Problem825(t *testing.T) { qs := []question825{ { para825{[]int{16, 16}}, ans825{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0825.Friends-Of-Appropriate-Ages/825. Friends Of Appropriate Ages.go
leetcode/0825.Friends-Of-Appropriate-Ages/825. Friends Of Appropriate Ages.go
package leetcocde import "sort" // 解法一 前缀和,时间复杂度 O(n) func numFriendRequests(ages []int) int { count, prefixSum, res := make([]int, 121), make([]int, 121), 0 for _, age := range ages { count[age]++ } for i := 1; i < 121; i++ { prefixSum[i] = prefixSum[i-1] + count[i] } for i := 15; i < 121; i++ { if count...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array.go
leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array.go
package leetcode func getMaximumGenerated(n int) int { if n == 0 { return 0 } nums, max := make([]int, n+1), 0 nums[0], nums[1] = 0, 1 for i := 0; i <= n; i++ { if nums[i] > max { max = nums[i] } if 2*i >= 2 && 2*i <= n { nums[2*i] = nums[i] } if 2*i+1 >= 2 && 2*i+1 <= n { nums[2*i+1] = nums[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array_test.go
leetcode/1646.Get-Maximum-in-Generated-Array/1646. Get Maximum in Generated Array_test.go
package leetcode import ( "fmt" "testing" ) type question1646 struct { para1646 ans1646 } // para 是参数 // one 代表第一个参数 type para1646 struct { n int } // ans 是答案 // one 代表第一个答案 type ans1646 struct { one int } func Test_Problem1646(t *testing.T) { qs := []question1646{ { para1646{7}, ans1646{3}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0878.Nth-Magical-Number/878. Nth Magical Number.go
leetcode/0878.Nth-Magical-Number/878. Nth Magical Number.go
package leetcode func nthMagicalNumber(N int, A int, B int) int { low, high := int64(0), int64(1*1e14) for low < high { mid := low + (high-low)>>1 if calNthMagicalCount(mid, int64(A), int64(B)) < int64(N) { low = mid + 1 } else { high = mid } } return int(low) % 1000000007 } func calNthMagicalCount(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0878.Nth-Magical-Number/878. Nth Magical Number_test.go
leetcode/0878.Nth-Magical-Number/878. Nth Magical Number_test.go
package leetcode import ( "fmt" "testing" ) type question878 struct { para878 ans878 } // para 是参数 // one 代表第一个参数 type para878 struct { n int a int b int } // ans 是答案 // one 代表第一个答案 type ans878 struct { one int } func Test_Problem878(t *testing.T) { qs := []question878{ { para878{1, 2, 3}, ans87...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1293.Shortest-Path-in-a-Grid-with-Obstacles-Elimination/1293. Shortest Path in a Grid with Obstacles Elimination.go
leetcode/1293.Shortest-Path-in-a-Grid-with-Obstacles-Elimination/1293. Shortest Path in a Grid with Obstacles Elimination.go
package leetcode var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } type pos struct { x, y int obstacle int step int } func shortestPath(grid [][]int, k int) int { queue, m, n := []pos{}, len(grid), len(grid[0]) visitor := make([][][]int, m) if len(grid) == 1 && len(grid[0]) == 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/1293.Shortest-Path-in-a-Grid-with-Obstacles-Elimination/1293. Shortest Path in a Grid with Obstacles Elimination_test.go
leetcode/1293.Shortest-Path-in-a-Grid-with-Obstacles-Elimination/1293. Shortest Path in a Grid with Obstacles Elimination_test.go
package leetcode import ( "fmt" "testing" ) type question1293 struct { para1293 ans1293 } // para 是参数 // one 代表第一个参数 type para1293 struct { grid [][]int k int } // ans 是答案 // one 代表第一个答案 type ans1293 struct { one int } func Test_Problem1293(t *testing.T) { qs := []question1293{ { para1293{[][]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1005.Maximize-Sum-Of-Array-After-K-Negations/1005. Maximize Sum Of Array After K Negations.go
leetcode/1005.Maximize-Sum-Of-Array-After-K-Negations/1005. Maximize Sum Of Array After K Negations.go
package leetcode import ( "sort" ) func largestSumAfterKNegations(A []int, K int) int { sort.Ints(A) minIdx := 0 for i := 0; i < K; i++ { A[minIdx] = -A[minIdx] if A[minIdx+1] < A[minIdx] { minIdx++ } } sum := 0 for _, a := range A { sum += a } return sum }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1005.Maximize-Sum-Of-Array-After-K-Negations/1005. Maximize Sum Of Array After K Negations_test.go
leetcode/1005.Maximize-Sum-Of-Array-After-K-Negations/1005. Maximize Sum Of Array After K Negations_test.go
package leetcode import ( "fmt" "testing" ) type question1005 struct { para1005 ans1005 } // para 是参数 // one 代表第一个参数 type para1005 struct { one []int two int } // ans 是答案 // one 代表第一个答案 type ans1005 struct { one int } func Test_Problem1005(t *testing.T) { qs := []question1005{ { para1005{[]int{4, 2,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0014.Longest-Common-Prefix/14.Longest Common Prefix_test.go
leetcode/0014.Longest-Common-Prefix/14.Longest Common Prefix_test.go
package leetcode import ( "fmt" "testing" ) type question14 struct { para14 ans14 } // para 是参数 type para14 struct { strs []string } // ans 是答案 type ans14 struct { ans string } func Test_Problem14(t *testing.T) { qs := []question14{ { para14{[]string{"flower", "flow", "flight"}}, ans14{"fl"}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0014.Longest-Common-Prefix/14.Longest Common Prefix.go
leetcode/0014.Longest-Common-Prefix/14.Longest Common Prefix.go
package leetcode func longestCommonPrefix(strs []string) string { prefix := strs[0] for i := 1; i < len(strs); i++ { for j := 0; j < len(prefix); j++ { if len(strs[i]) <= j || strs[i][j] != prefix[j] { prefix = prefix[0:j] break } } } return prefix }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1619.Mean-of-Array-After-Removing-Some-Elements/1619. Mean of Array After Removing Some Elements.go
leetcode/1619.Mean-of-Array-After-Removing-Some-Elements/1619. Mean of Array After Removing Some Elements.go
package leetcode import "sort" func trimMean(arr []int) float64 { sort.Ints(arr) n, sum := len(arr), 0 for i := n / 20; i < n-(n/20); i++ { sum += arr[i] } return float64(sum) / float64((n - (n / 10))) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1619.Mean-of-Array-After-Removing-Some-Elements/1619. Mean of Array After Removing Some Elements_test.go
leetcode/1619.Mean-of-Array-After-Removing-Some-Elements/1619. Mean of Array After Removing Some Elements_test.go
package leetcode import ( "fmt" "testing" ) type question1619 struct { para1619 ans1619 } // para 是参数 // one 代表第一个参数 type para1619 struct { p []int } // ans 是答案 // one 代表第一个答案 type ans1619 struct { one float64 } func Test_Problem1619(t *testing.T) { qs := []question1619{ { para1619{[]int{1, 2, 2, 2, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0202.Happy-Number/202. Happy Number.go
leetcode/0202.Happy-Number/202. Happy Number.go
package leetcode func isHappy(n int) bool { record := map[int]int{} for n != 1 { record[n] = n n = getSquareOfDigits(n) for _, previous := range record { if n == previous { return false } } } return true } func getSquareOfDigits(n int) int { squareOfDigits := 0 temporary := n for temporary !=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0202.Happy-Number/202. Happy Number_test.go
leetcode/0202.Happy-Number/202. Happy Number_test.go
package leetcode import ( "fmt" "testing" ) type question202 struct { para202 ans202 } // para 是参数 // one 代表第一个参数 type para202 struct { one int } // ans 是答案 // one 代表第一个答案 type ans202 struct { one bool } func Test_Problem202(t *testing.T) { qs := []question202{ { para202{202}, ans202{false}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0485.Max-Consecutive-Ones/485. Max Consecutive Ones_test.go
leetcode/0485.Max-Consecutive-Ones/485. Max Consecutive Ones_test.go
package leetcode import ( "fmt" "testing" ) type question485 struct { para485 ans485 } // para 是参数 // one 代表第一个参数 type para485 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans485 struct { one int } func Test_Problem485(t *testing.T) { qs := []question485{ { para485{[]int{1, 1, 0, 1, 1, 1}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0485.Max-Consecutive-Ones/485. Max Consecutive Ones.go
leetcode/0485.Max-Consecutive-Ones/485. Max Consecutive Ones.go
package leetcode func findMaxConsecutiveOnes(nums []int) int { maxCount, currentCount := 0, 0 for _, v := range nums { if v == 1 { currentCount++ } else { currentCount = 0 } if currentCount > maxCount { maxCount = currentCount } } return maxCount }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0067.Add-Binary/67. Add Binary.go
leetcode/0067.Add-Binary/67. Add Binary.go
package leetcode import ( "strconv" "strings" ) func addBinary(a string, b string) string { if len(b) > len(a) { a, b = b, a } res := make([]string, len(a)+1) i, j, k, c := len(a)-1, len(b)-1, len(a), 0 for i >= 0 && j >= 0 { ai, _ := strconv.Atoi(string(a[i])) bj, _ := strconv.Atoi(string(b[j])) res[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0067.Add-Binary/67. Add Binary_test.go
leetcode/0067.Add-Binary/67. Add Binary_test.go
package leetcode import ( "fmt" "testing" ) type question67 struct { para67 ans67 } // para 是参数 // one 代表第一个参数 type para67 struct { a string b string } // ans 是答案 // one 代表第一个答案 type ans67 struct { one string } func Test_Problem67(t *testing.T) { qs := []question67{ { para67{"11", "1"}, ans67{"10...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0575.Distribute-Candies/575. Distribute Candies.go
leetcode/0575.Distribute-Candies/575. Distribute Candies.go
package leetcode func distributeCandies(candies []int) int { n, m := len(candies), make(map[int]struct{}, len(candies)) for _, candy := range candies { m[candy] = struct{}{} } res := len(m) if n/2 < res { return n / 2 } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0575.Distribute-Candies/575. Distribute Candies_test.go
leetcode/0575.Distribute-Candies/575. Distribute Candies_test.go
package leetcode import ( "fmt" "testing" ) type question575 struct { para575 ans575 } // para 是参数 // one 代表第一个参数 type para575 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans575 struct { one int } func Test_Problem575(t *testing.T) { qs := []question575{ { para575{[]int{1, 1, 2, 2, 3, 3}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0746.Min-Cost-Climbing-Stairs/746. Min Cost Climbing Stairs.go
leetcode/0746.Min-Cost-Climbing-Stairs/746. Min Cost Climbing Stairs.go
package leetcode // 解法一 DP func minCostClimbingStairs(cost []int) int { dp := make([]int, len(cost)) dp[0], dp[1] = cost[0], cost[1] for i := 2; i < len(cost); i++ { dp[i] = cost[i] + min(dp[i-2], dp[i-1]) } return min(dp[len(cost)-2], dp[len(cost)-1]) } func min(a int, b int) int { if a > b { return b } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0746.Min-Cost-Climbing-Stairs/746. Min Cost Climbing Stairs_test.go
leetcode/0746.Min-Cost-Climbing-Stairs/746. Min Cost Climbing Stairs_test.go
package leetcode import ( "fmt" "testing" ) type question746 struct { para746 ans746 } // para 是参数 // one 代表第一个参数 type para746 struct { c []int } // ans 是答案 // one 代表第一个答案 type ans746 struct { one int } func Test_Problem746(t *testing.T) { qs := []question746{ { para746{[]int{10, 15, 20}}, ans746{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0073.Set-Matrix-Zeroes/73. Set Matrix Zeroes.go
leetcode/0073.Set-Matrix-Zeroes/73. Set Matrix Zeroes.go
package leetcode func setZeroes(matrix [][]int) { if len(matrix) == 0 || len(matrix[0]) == 0 { return } isFirstRowExistZero, isFirstColExistZero := false, false for i := 0; i < len(matrix); i++ { if matrix[i][0] == 0 { isFirstColExistZero = true break } } for j := 0; j < len(matrix[0]); j++ { if ma...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0073.Set-Matrix-Zeroes/73. Set Matrix Zeroes_test.go
leetcode/0073.Set-Matrix-Zeroes/73. Set Matrix Zeroes_test.go
package leetcode import ( "fmt" "testing" ) type question73 struct { para73 ans73 } // para 是参数 // one 代表第一个参数 type para73 struct { matrix [][]int } // ans 是答案 // one 代表第一个答案 type ans73 struct { } func Test_Problem73(t *testing.T) { qs := []question73{ { para73{[][]int{ {0, 1, 2, 0}, {3, 4, 5,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0786.K-th-Smallest-Prime-Fraction/786. K-th Smallest Prime Fraction_test.go
leetcode/0786.K-th-Smallest-Prime-Fraction/786. K-th Smallest Prime Fraction_test.go
package leetcode import ( "fmt" "testing" ) type question786 struct { para786 ans786 } // para 是参数 // one 代表第一个参数 type para786 struct { A []int K int } // ans 是答案 // one 代表第一个答案 type ans786 struct { one []int } func Test_Problem786(t *testing.T) { qs := []question786{ { para786{[]int{1, 2, 3, 5}, 3}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0786.K-th-Smallest-Prime-Fraction/786. K-th Smallest Prime Fraction.go
leetcode/0786.K-th-Smallest-Prime-Fraction/786. K-th Smallest Prime Fraction.go
package leetcode import ( "sort" ) // 解法一 二分搜索 func kthSmallestPrimeFraction(A []int, K int) []int { low, high, n := 0.0, 1.0, len(A) // 因为是在小数内使用二分查找,无法像在整数范围内那样通过 mid+1 和边界判断来终止循环 // 所以此处根据 count 来结束循环 for { mid, count, p, q, j := (high+low)/2.0, 0, 0, 1, 0 for i := 0; i < n; i++ { for j < n && float64(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0488.Zuma-Game/488.Zuma Game_test.go
leetcode/0488.Zuma-Game/488.Zuma Game_test.go
package leetcode import ( "fmt" "testing" ) type question488 struct { para488 ans488 } // para 是参数 type para488 struct { board string hand string } // ans 是答案 type ans488 struct { ans int } func Test_Problem488(t *testing.T) { qs := []question488{ { para488{"WRRBBW", "RB"}, ans488{-1}, }, {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0488.Zuma-Game/488.Zuma Game.go
leetcode/0488.Zuma-Game/488.Zuma Game.go
package leetcode func findMinStep(board string, hand string) int { q := [][]string{{board, hand}} mp := make(map[string]bool) minStep := 0 for len(q) > 0 { length := len(q) minStep++ for length > 0 { length-- cur := q[0] q = q[1:] curB, curH := cur[0], cur[1] for i := 0; i < len(curB); i++ { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0397.Integer-Replacement/397. Integer Replacement.go
leetcode/0397.Integer-Replacement/397. Integer Replacement.go
package leetcode func integerReplacement(n int) int { res := 0 for n > 1 { if (n & 1) == 0 { // 判断是否是偶数 n >>= 1 } else if (n+1)%4 == 0 && n != 3 { // 末尾 2 位为 11 n++ } else { // 末尾 2 位为 01 n-- } res++ } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0397.Integer-Replacement/397. Integer Replacement_test.go
leetcode/0397.Integer-Replacement/397. Integer Replacement_test.go
package leetcode import ( "fmt" "testing" ) type question397 struct { para397 ans397 } // para 是参数 // one 代表第一个参数 type para397 struct { s int } // ans 是答案 // one 代表第一个答案 type ans397 struct { one int } func Test_Problem397(t *testing.T) { qs := []question397{ { para397{8}, ans397{3}, }, { p...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990316.Remove-Duplicate-Letters/316. Remove Duplicate Letters_test.go
leetcode/9990316.Remove-Duplicate-Letters/316. Remove Duplicate Letters_test.go
package leetcode import ( "fmt" "testing" ) type question316 struct { para316 ans316 } // para 是参数 // one 代表第一个参数 type para316 struct { one string } // ans 是答案 // one 代表第一个答案 type ans316 struct { one string } func Test_Problem316(t *testing.T) { qs := []question316{ { para316{"bcabc"}, ans316{"abc...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990316.Remove-Duplicate-Letters/316. Remove Duplicate Letters.go
leetcode/9990316.Remove-Duplicate-Letters/316. Remove Duplicate Letters.go
package leetcode func removeDuplicateLetters(s string) string { return "" }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0141.Linked-List-Cycle/141. Linked List Cycle_test.go
leetcode/0141.Linked-List-Cycle/141. Linked List Cycle_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question141 struct { para141 ans141 } // para 是参数 // one 代表第一个参数 type para141 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans141 struct { one bool } func Test_Problem141(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/0141.Linked-List-Cycle/141. Linked List Cycle.go
leetcode/0141.Linked-List-Cycle/141. Linked List Cycle.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 hasCycle(head *ListNode) bool { fast := head slow := head for fas...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0969.Pancake-Sorting/969. Pancake Sorting.go
leetcode/0969.Pancake-Sorting/969. Pancake Sorting.go
package leetcode func pancakeSort(A []int) []int { if len(A) == 0 { return []int{} } right := len(A) var ( ans []int ) for right > 0 { idx := find(A, right) if idx != right-1 { reverse969(A, 0, idx) reverse969(A, 0, right-1) ans = append(ans, idx+1, right) } right-- } return ans } func r...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0969.Pancake-Sorting/969. Pancake Sorting_test.go
leetcode/0969.Pancake-Sorting/969. Pancake Sorting_test.go
package leetcode import ( "fmt" "testing" ) type question969 struct { para969 ans969 } // para 是参数 // one 代表第一个参数 type para969 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans969 struct { one []int } func Test_Problem969(t *testing.T) { qs := []question969{ { para969{[]int{}}, ans969{[]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0095.Unique-Binary-Search-Trees-II/95. Unique Binary Search Trees II_test.go
leetcode/0095.Unique-Binary-Search-Trees-II/95. Unique Binary Search Trees II_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question95 struct { para95 ans95 } // para 是参数 // one 代表第一个参数 type para95 struct { one int } // ans 是答案 // one 代表第一个答案 type ans95 struct { one []*TreeNode } func Test_Problem95(t *testing.T) { qs := []question95...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0095.Unique-Binary-Search-Trees-II/95. Unique Binary Search Trees II.go
leetcode/0095.Unique-Binary-Search-Trees-II/95. Unique Binary Search Trees II.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 generateTrees(n int) []*TreeNode { if n == 0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0142.Linked-List-Cycle-II/142. Linked List Cycle II_test.go
leetcode/0142.Linked-List-Cycle-II/142. Linked List Cycle II_test.go
package leetcode import "testing" func Test_Problem142(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/0142.Linked-List-Cycle-II/142. Linked List Cycle II.go
leetcode/0142.Linked-List-Cycle-II/142. Linked List Cycle II.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // ListNode define type ListNode = structures.ListNode /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func detectCycle(head *ListNode) *ListNode { if head == nil || head.Next ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1396.Design-Underground-System/1396. Design Underground System_test.go
leetcode/1396.Design-Underground-System/1396. Design Underground System_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem(t *testing.T) { undergroundSystem := Constructor() undergroundSystem.CheckIn(45, "Leyton", 3) undergroundSystem.CheckIn(32, "Paradise", 8) undergroundSystem.CheckIn(27, "Leyton", 10) undergroundSystem.CheckOut(45, "Waterloo", 15) undergroundSystem....
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1396.Design-Underground-System/1396. Design Underground System.go
leetcode/1396.Design-Underground-System/1396. Design Underground System.go
package leetcode type checkin struct { station string time int } type stationTime struct { sum, count float64 } type UndergroundSystem struct { checkins map[int]*checkin stationTimes map[string]map[string]*stationTime } func Constructor() UndergroundSystem { return UndergroundSystem{ make(map[int]*ch...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies_test.go
leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies_test.go
package leetcode import ( "fmt" "testing" ) type question1203 struct { para1203 ans1203 } // para 是参数 // one 代表第一个参数 type para1203 struct { n int m int group []int beforeItems [][]int } // ans 是答案 // one 代表第一个答案 type ans1203 struct { one []int } func Test_Problem1203(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/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies.go
leetcode/1203.Sort-Items-by-Groups-Respecting-Dependencies/1203. Sort Items by Groups Respecting Dependencies.go
package leetcode // 解法一 拓扑排序版的 DFS func sortItems(n int, m int, group []int, beforeItems [][]int) []int { groups, inDegrees := make([][]int, n+m), make([]int, n+m) for i, g := range group { if g > -1 { g += n groups[g] = append(groups[g], i) inDegrees[i]++ } } for i, ancestors := range beforeItems { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0374.Guess-Number-Higher-or-Lower/374. Guess Number Higher or Lower.go
leetcode/0374.Guess-Number-Higher-or-Lower/374. Guess Number Higher or Lower.go
package leetcode import "sort" /** * Forward declaration of guess API. * @param num your guess * @return -1 if num is lower than the guess number * 1 if num is higher than the guess number * otherwise return 0 * func guess(num int) int; */ func guessNumber(n int) int { return s...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0374.Guess-Number-Higher-or-Lower/374. Guess Number Higher or Lower_test.go
leetcode/0374.Guess-Number-Higher-or-Lower/374. Guess Number Higher or Lower_test.go
package leetcode import ( "fmt" "testing" ) type question374 struct { para374 ans374 } // para 是参数 // one 代表第一个参数 type para374 struct { n int } // ans 是答案 // one 代表第一个答案 type ans374 struct { one int } func Test_Problem374(t *testing.T) { qs := []question374{ { para374{10}, ans374{6}, }, { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0911.Online-Election/911. Online Election_test.go
leetcode/0911.Online-Election/911. Online Election_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem911(t *testing.T) { obj := Constructor911([]int{0, 1, 1, 0, 0, 1, 0}, []int{0, 5, 10, 15, 20, 25, 30}) fmt.Printf("obj.Q[3] = %v\n", obj.Q(3)) // 0 fmt.Printf("obj.Q[12] = %v\n", obj.Q(12)) // 1 fmt.Printf("obj.Q[25] = %v\n", obj.Q(25)) // 1 fmt.Pr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0911.Online-Election/911. Online Election.go
leetcode/0911.Online-Election/911. Online Election.go
package leetcode import ( "sort" ) // TopVotedCandidate define type TopVotedCandidate struct { persons []int times []int } // Constructor911 define func Constructor911(persons []int, times []int) TopVotedCandidate { leaders, votes := make([]int, len(persons)), make([]int, len(persons)) leader := persons[0] f...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1463.Cherry-Pickup-II/1463. Cherry Pickup II_test.go
leetcode/1463.Cherry-Pickup-II/1463. Cherry Pickup II_test.go
package leetcode import ( "fmt" "testing" ) type question1463 struct { para1463 ans1463 } type para1463 struct { grid [][]int } type ans1463 struct { ans int } func Test_Problem1463(t *testing.T) { qs := []question1463{ { para1463{[][]int{ {3, 1, 1}, {2, 5, 1}, {1, 5, 5}, {2, 1, 1}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1463.Cherry-Pickup-II/1463. Cherry Pickup II.go
leetcode/1463.Cherry-Pickup-II/1463. Cherry Pickup II.go
package leetcode func cherryPickup(grid [][]int) int { rows, cols := len(grid), len(grid[0]) dp := make([][][]int, rows) for i := 0; i < rows; i++ { dp[i] = make([][]int, cols) for j := 0; j < cols; j++ { dp[i][j] = make([]int, cols) } } for i := 0; i < rows; i++ { for j := 0; j <= i && j < cols; j++ {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0378.Kth-Smallest-Element-in-a-Sorted-Matrix/378. Kth Smallest Element in a Sorted Matrix.go
leetcode/0378.Kth-Smallest-Element-in-a-Sorted-Matrix/378. Kth Smallest Element in a Sorted Matrix.go
package leetcode import ( "container/heap" ) // 解法一 二分搜索 func kthSmallest378(matrix [][]int, k int) int { m, n, low := len(matrix), len(matrix[0]), matrix[0][0] high := matrix[m-1][n-1] + 1 for low < high { mid := low + (high-low)>>1 // 如果 count 比 k 小,在大值的那一半继续二分搜索 if counterKthSmall(m, n, mid, matrix) >= k...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0378.Kth-Smallest-Element-in-a-Sorted-Matrix/378. Kth Smallest Element in a Sorted Matrix_test.go
leetcode/0378.Kth-Smallest-Element-in-a-Sorted-Matrix/378. Kth Smallest Element in a Sorted Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question378 struct { para378 ans378 } // para 是参数 // one 代表第一个参数 type para378 struct { matrix [][]int k int } // ans 是答案 // one 代表第一个答案 type ans378 struct { one int } func Test_Problem378(t *testing.T) { qs := []question378{ { para378{[][]int{{1,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0980.Unique-Paths-III/980. Unique Paths III.go
leetcode/0980.Unique-Paths-III/980. Unique Paths III.go
package leetcode var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } func uniquePathsIII(grid [][]int) int { visited := make([][]bool, len(grid)) for i := 0; i < len(visited); i++ { visited[i] = make([]bool, len(grid[0])) } res, empty, startx, starty, endx, endy, path := 0, 0, 0, 0, 0, 0, []int{} for i,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0980.Unique-Paths-III/980. Unique Paths III_test.go
leetcode/0980.Unique-Paths-III/980. Unique Paths III_test.go
package leetcode import ( "fmt" "testing" ) type question980 struct { para980 ans980 } // para 是参数 // one 代表第一个参数 type para980 struct { grid [][]int } // ans 是答案 // one 代表第一个答案 type ans980 struct { one int } func Test_Problem980(t *testing.T) { qs := []question980{ { para980{[][]int{ {1, 0, 0, 0}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0811.Subdomain-Visit-Count/811. Subdomain Visit Count_test.go
leetcode/0811.Subdomain-Visit-Count/811. Subdomain Visit Count_test.go
package leetcode import ( "fmt" "testing" ) type question811 struct { para811 ans811 } // para 是参数 // one 代表第一个参数 type para811 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans811 struct { one []string } func Test_Problem811(t *testing.T) { qs := []question811{ { para811{[]string{"9001 discu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0811.Subdomain-Visit-Count/811. Subdomain Visit Count.go
leetcode/0811.Subdomain-Visit-Count/811. Subdomain Visit Count.go
package leetcode import ( "strconv" "strings" ) // 解法一 func subdomainVisits(cpdomains []string) []string { result := make([]string, 0) if len(cpdomains) == 0 { return result } domainCountMap := make(map[string]int, 0) for _, domain := range cpdomains { countDomain := strings.Split(domain, " ") allDomains...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0376.Wiggle-Subsequence/376. Wiggle Subsequence_test.go
leetcode/0376.Wiggle-Subsequence/376. Wiggle Subsequence_test.go
package leetcode import ( "fmt" "testing" ) type question376 struct { para376 ans376 } // para 是参数 // one 代表第一个参数 type para376 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans376 struct { one int } func Test_Problem376(t *testing.T) { qs := []question376{ { para376{[]int{1, 7, 4, 9, 2, 5}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0376.Wiggle-Subsequence/376. Wiggle Subsequence.go
leetcode/0376.Wiggle-Subsequence/376. Wiggle Subsequence.go
package leetcode func wiggleMaxLength(nums []int) int { if len(nums) < 2 { return len(nums) } res := 1 prevDiff := nums[1] - nums[0] if prevDiff != 0 { res = 2 } for i := 2; i < len(nums); i++ { diff := nums[i] - nums[i-1] if diff > 0 && prevDiff <= 0 || diff < 0 && prevDiff >= 0 { res++ prevDiff ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0057.Insert-Interval/57. Insert Interval.go
leetcode/0057.Insert-Interval/57. Insert Interval.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // Interval define type Interval = structures.Interval /** * Definition for an interval. * type Interval struct { * Start int * End int * } */ func insert(intervals []Interval, newInterval Interval) []Interval { res := make([]I...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0057.Insert-Interval/57. Insert Interval_test.go
leetcode/0057.Insert-Interval/57. Insert Interval_test.go
package leetcode import ( "fmt" "testing" ) type question57 struct { para57 ans57 } // para 是参数 // one 代表第一个参数 type para57 struct { one []Interval two Interval } // ans 是答案 // one 代表第一个答案 type ans57 struct { one []Interval } func Test_Problem57(t *testing.T) { qs := []question57{ { para57{[]Interval...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0745.Prefix-and-Suffix-Search/745. Prefix and Suffix Search.go
leetcode/0745.Prefix-and-Suffix-Search/745. Prefix and Suffix Search.go
package leetcode import "strings" // 解法一 查找时间复杂度 O(1) type WordFilter struct { words map[string]int } func Constructor745(words []string) WordFilter { wordsMap := make(map[string]int, len(words)*5) for k := 0; k < len(words); k++ { for i := 0; i <= 10 && i <= len(words[k]); i++ { for j := len(words[k]); 0 <=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0745.Prefix-and-Suffix-Search/745. Prefix and Suffix Search_test.go
leetcode/0745.Prefix-and-Suffix-Search/745. Prefix and Suffix Search_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem745(t *testing.T) { obj := Constructor745([]string{"apple"}) fmt.Printf("obj = %v\n", obj) param1 := obj.F("a", "e") fmt.Printf("param_1 = %v obj = %v\n", param1, obj) param2 := obj.F("b", "") fmt.Printf("param_2 = %v obj = %v\n", param2, obj) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1143.Longest-Common-Subsequence/1143. Longest Common Subsequence_test.go
leetcode/1143.Longest-Common-Subsequence/1143. Longest Common Subsequence_test.go
package leetcode import ( "fmt" "testing" ) type question1143 struct { para1143 ans1143 } // para 是参数 // one 代表第一个参数 type para1143 struct { text1 string text2 string } // ans 是答案 // one 代表第一个答案 type ans1143 struct { one int } func Test_Problem1143(t *testing.T) { qs := []question1143{ { para1143{"ab...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1143.Longest-Common-Subsequence/1143. Longest Common Subsequence.go
leetcode/1143.Longest-Common-Subsequence/1143. Longest Common Subsequence.go
package leetcode func longestCommonSubsequence(text1 string, text2 string) int { if len(text1) == 0 || len(text2) == 0 { return 0 } dp := make([][]int, len(text1)+1) for i := range dp { dp[i] = make([]int, len(text2)+1) } for i := 1; i < len(text1)+1; i++ { for j := 1; j < len(text2)+1; j++ { if text1[i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0685.Redundant-Connection-II/685. Redundant Connection II_test.go
leetcode/0685.Redundant-Connection-II/685. Redundant Connection II_test.go
package leetcode import ( "fmt" "testing" ) type question685 struct { para685 ans685 } // para 是参数 // one 代表第一个参数 type para685 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans685 struct { one []int } func Test_Problem685(t *testing.T) { qs := []question685{ { para685{[][]int{{3, 5}, {1, 3}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0685.Redundant-Connection-II/685. Redundant Connection II.go
leetcode/0685.Redundant-Connection-II/685. Redundant Connection II.go
package leetcode func findRedundantDirectedConnection(edges [][]int) []int { if len(edges) == 0 { return []int{} } parent, candidate1, candidate2 := make([]int, len(edges)+1), []int{}, []int{} for _, edge := range edges { if parent[edge[1]] == 0 { parent[edge[1]] = edge[0] } else { // 如果一个节点已经有父亲节点了,说明入度已...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness.go
leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness.go
package leetcode import ( "math" ) func getMaxGridHappiness(m int, n int, introvertsCount int, extrovertsCount int) int { // lineStatus 将每一行中 3 种状态进行编码,空白 - 0,内向人 - 1,外向人 - 2,每行状态用三进制表示 // lineStatusList[729][6] 每一行的三进制表示 // introvertsCountInner[729] 每一个 lineStatus 包含的内向人数 // extrovertsCountInner[729] 每...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness_test.go
leetcode/1659.Maximize-Grid-Happiness/1659. Maximize Grid Happiness_test.go
package leetcode import ( "fmt" "testing" ) type question1659 struct { para1659 ans1659 } // para 是参数 // one 代表第一个参数 type para1659 struct { m int n int introvertsCount int extrovertsCount int } // ans 是答案 // one 代表第一个答案 type ans1659 struct { one int } func Test_Problem1659(t *t...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0726.Number-of-Atoms/726. Number of Atoms.go
leetcode/0726.Number-of-Atoms/726. Number of Atoms.go
package leetcode import ( "sort" "strconv" "strings" ) type atom struct { name string cnt int } type atoms []atom func (this atoms) Len() int { return len(this) } func (this atoms) Less(i, j int) bool { return strings.Compare(this[i].name, this[j].name) < 0 } func (this atoms) Swap(i, j int) { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0726.Number-of-Atoms/726. Number of Atoms_test.go
leetcode/0726.Number-of-Atoms/726. Number of Atoms_test.go
package leetcode import ( "fmt" "testing" ) type question726 struct { para726 ans726 } // para 是参数 // one 代表第一个参数 type para726 struct { one string } // ans 是答案 // one 代表第一个答案 type ans726 struct { one string } func Test_Problem726(t *testing.T) { qs := []question726{ { para726{"H200P"}, ans726{"H20...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0031.Next-Permutation/31. Next Permutation_test.go
leetcode/0031.Next-Permutation/31. Next Permutation_test.go
package leetcode import ( "fmt" "testing" ) type question31 struct { para31 ans31 } // para 是参数 // one 代表第一个参数 type para31 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans31 struct { one []int } func Test_Problem31(t *testing.T) { qs := []question31{ { para31{[]int{1, 2, 3}}, ans31{[]int{1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0031.Next-Permutation/31. Next Permutation.go
leetcode/0031.Next-Permutation/31. Next Permutation.go
package leetcode // 解法一 func nextPermutation(nums []int) { i, j := 0, 0 for i = len(nums) - 2; i >= 0; i-- { if nums[i] < nums[i+1] { break } } if i >= 0 { for j = len(nums) - 1; j > i; j-- { if nums[j] > nums[i] { break } } swap(&nums, i, j) } reverse(&nums, i+1, len(nums)-1) } func reve...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0985.Sum-of-Even-Numbers-After-Queries/985. Sum of Even Numbers After Queries_test.go
leetcode/0985.Sum-of-Even-Numbers-After-Queries/985. Sum of Even Numbers After Queries_test.go
package leetcode import ( "fmt" "testing" ) type question985 struct { para985 ans985 } // para 是参数 // one 代表第一个参数 type para985 struct { A []int queries [][]int } // ans 是答案 // one 代表第一个答案 type ans985 struct { one []int } func Test_Problem985(t *testing.T) { qs := []question985{ { para985{[]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0985.Sum-of-Even-Numbers-After-Queries/985. Sum of Even Numbers After Queries.go
leetcode/0985.Sum-of-Even-Numbers-After-Queries/985. Sum of Even Numbers After Queries.go
package leetcode func sumEvenAfterQueries(A []int, queries [][]int) []int { cur, res := 0, []int{} for _, v := range A { if v%2 == 0 { cur += v } } for _, q := range queries { if A[q[1]]%2 == 0 { cur -= A[q[1]] } A[q[1]] += q[0] if A[q[1]]%2 == 0 { cur += A[q[1]] } res = append(res, cur) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0216.Combination-Sum-III/216. Combination Sum III_test.go
leetcode/0216.Combination-Sum-III/216. Combination Sum III_test.go
package leetcode import ( "fmt" "testing" ) type question216 struct { para216 ans216 } // para 是参数 // one 代表第一个参数 type para216 struct { n int k int } // ans 是答案 // one 代表第一个答案 type ans216 struct { one [][]int } func Test_Problem216(t *testing.T) { qs := []question216{ { para216{3, 7}, ans216{[][]...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0216.Combination-Sum-III/216. Combination Sum III.go
leetcode/0216.Combination-Sum-III/216. Combination Sum III.go
package leetcode func combinationSum3(k int, n int) [][]int { if k == 0 { return [][]int{} } c, res := []int{}, [][]int{} findcombinationSum3(k, n, 1, c, &res) return res } func findcombinationSum3(k, target, index int, c []int, res *[][]int) { if target == 0 { if len(c) == k { b := make([]int, len(c)) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0167.Two-Sum-II-Input-array-is-sorted/167. Two Sum II - Input array is sorted.go
leetcode/0167.Two-Sum-II-Input-array-is-sorted/167. Two Sum II - Input array is sorted.go
package leetcode // 解法一 这一题可以利用数组有序的特性 func twoSum167(numbers []int, target int) []int { i, j := 0, len(numbers)-1 for i < j { if numbers[i]+numbers[j] == target { return []int{i + 1, j + 1} } if numbers[i]+numbers[j] < target { i++ } else { j-- } } return nil } // 解法二 不管数组是否有序,空间复杂度比上一种解法要多 O(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0167.Two-Sum-II-Input-array-is-sorted/167. Two Sum II - Input array is sorted_test.go
leetcode/0167.Two-Sum-II-Input-array-is-sorted/167. Two Sum II - Input array is sorted_test.go
package leetcode import ( "fmt" "testing" ) type question167 struct { para167 ans167 } // para 是参数 // one 代表第一个参数 type para167 struct { one []int two int } // ans 是答案 // one 代表第一个答案 type ans167 struct { one []int } func Test_Problem167(t *testing.T) { qs := []question167{ { para167{[]int{2, 7, 11, 1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0045.Jump-Game-II/45. Jump Game II_test.go
leetcode/0045.Jump-Game-II/45. Jump Game II_test.go
package leetcode import ( "fmt" "testing" ) type question45 struct { para45 ans45 } // para 是参数 // one 代表第一个参数 type para45 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans45 struct { one int } func Test_Problem45(t *testing.T) { qs := []question45{ { para45{[]int{2, 3, 1, 1, 4}}, ans45{2},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0045.Jump-Game-II/45. Jump Game II.go
leetcode/0045.Jump-Game-II/45. Jump Game II.go
package leetcode func jump(nums []int) int { if len(nums) == 1 { return 0 } needChoose, canReach, step := 0, 0, 0 for i, x := range nums { if i+x > canReach { canReach = i + x if canReach >= len(nums)-1 { return step + 1 } } if i == needChoose { needChoose = canReach step++ } } retur...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0921.Minimum-Add-to-Make-Parentheses-Valid/921. Minimum Add to Make Parentheses Valid.go
leetcode/0921.Minimum-Add-to-Make-Parentheses-Valid/921. Minimum Add to Make Parentheses Valid.go
package leetcode func minAddToMakeValid(S string) int { if len(S) == 0 { return 0 } stack := make([]rune, 0) for _, v := range S { if v == '(' { stack = append(stack, v) } else if (v == ')') && len(stack) > 0 && stack[len(stack)-1] == '(' { stack = stack[:len(stack)-1] } else { stack = append(stac...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0921.Minimum-Add-to-Make-Parentheses-Valid/921. Minimum Add to Make Parentheses Valid_test.go
leetcode/0921.Minimum-Add-to-Make-Parentheses-Valid/921. Minimum Add to Make Parentheses Valid_test.go
package leetcode import ( "fmt" "testing" ) type question921 struct { para921 ans921 } // para 是参数 // one 代表第一个参数 type para921 struct { one string } // ans 是答案 // one 代表第一个答案 type ans921 struct { one int } func Test_Problem921(t *testing.T) { qs := []question921{ { para921{"())"}, ans921{1}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0436.Find-Right-Interval/436. Find Right Interval.go
leetcode/0436.Find-Right-Interval/436. Find Right Interval.go
package leetcode import ( "sort" "github.com/halfrost/LeetCode-Go/structures" ) // Interval define type Interval = structures.Interval // 解法一 利用系统函数 sort + 二分搜索 func findRightInterval(intervals [][]int) []int { intervalList := make(intervalList, len(intervals)) // 转换成 interval 类型 for i, v := range intervals { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0436.Find-Right-Interval/436. Find Right Interval_test.go
leetcode/0436.Find-Right-Interval/436. Find Right Interval_test.go
package leetcode import ( "fmt" "testing" ) type question436 struct { para436 ans436 } // para 是参数 // one 代表第一个参数 type para436 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans436 struct { one []int } func Test_Problem436(t *testing.T) { qs := []question436{ { para436{[][]int{{3, 4}, {2, 3}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0989.Add-to-Array-Form-of-Integer/989. Add to Array-Form of Integer.go
leetcode/0989.Add-to-Array-Form-of-Integer/989. Add to Array-Form of Integer.go
package leetcode func addToArrayForm(A []int, K int) []int { res := []int{} for i := len(A) - 1; i >= 0; i-- { sum := A[i] + K%10 K /= 10 if sum >= 10 { K++ sum -= 10 } res = append(res, sum) } for ; K > 0; K /= 10 { res = append(res, K%10) } reverse(res) return res } func reverse(A []int) { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0989.Add-to-Array-Form-of-Integer/989. Add to Array-Form of Integer_test.go
leetcode/0989.Add-to-Array-Form-of-Integer/989. Add to Array-Form of Integer_test.go
package leetcode import ( "fmt" "testing" ) type question989 struct { para989 ans989 } // para 是参数 // one 代表第一个参数 type para989 struct { A []int K int } // ans 是答案 // one 代表第一个答案 type ans989 struct { one []int } func Test_Problem989(t *testing.T) { qs := []question989{ { para989{[]int{1, 2, 0, 0}, 34...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0850.Rectangle-Area-II/850. Rectangle Area II_test.go
leetcode/0850.Rectangle-Area-II/850. Rectangle Area II_test.go
package leetcode import ( "fmt" "testing" ) type question850 struct { para850 ans850 } // para 是参数 // one 代表第一个参数 type para850 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans850 struct { one int } func Test_Problem850(t *testing.T) { qs := []question850{ { para850{[][]int{{0, 0, 3, 3}, {2, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0850.Rectangle-Area-II/850. Rectangle Area II.go
leetcode/0850.Rectangle-Area-II/850. Rectangle Area II.go
package leetcode import ( "sort" ) func rectangleArea(rectangles [][]int) int { sat, res := SegmentAreaTree{}, 0 posXMap, posX, posYMap, posY, lines := discretization850(rectangles) tmp := make([]int, len(posYMap)) for i := 0; i < len(tmp)-1; i++ { tmp[i] = posY[i+1] - posY[i] } sat.Init(tmp, func(i, j int) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0058.Length-of-Last-Word/58.Length of Last Word_test.go
leetcode/0058.Length-of-Last-Word/58.Length of Last Word_test.go
package leetcode import ( "fmt" "testing" ) type question58 struct { para58 ans58 } // para 是参数 type para58 struct { s string } // ans 是答案 type ans58 struct { ans int } func Test_Problem58(t *testing.T) { qs := []question58{ { para58{"Hello World"}, ans58{5}, }, { para58{" fly me to ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0058.Length-of-Last-Word/58.Length of Last Word.go
leetcode/0058.Length-of-Last-Word/58.Length of Last Word.go
package leetcode func lengthOfLastWord(s string) int { last := len(s) - 1 for last >= 0 && s[last] == ' ' { last-- } if last < 0 { return 0 } first := last for first >= 0 && s[first] != ' ' { first-- } return last - first }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1122.Relative-Sort-Array/1122. Relative Sort Array_test.go
leetcode/1122.Relative-Sort-Array/1122. Relative Sort Array_test.go
package leetcode import ( "fmt" "testing" ) type question1122 struct { para1122 ans1122 } // para 是参数 // one 代表第一个参数 type para1122 struct { arr1 []int arr2 []int } // ans 是答案 // one 代表第一个答案 type ans1122 struct { one []int } func Test_Problem1122(t *testing.T) { qs := []question1122{ { para1122{[]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1122.Relative-Sort-Array/1122. Relative Sort Array.go
leetcode/1122.Relative-Sort-Array/1122. Relative Sort Array.go
package leetcode import "sort" // 解法一 桶排序,时间复杂度 O(n^2) func relativeSortArray(A, B []int) []int { count := [1001]int{} for _, a := range A { count[a]++ } res := make([]int, 0, len(A)) for _, b := range B { for count[b] > 0 { res = append(res, b) count[b]-- } } for i := 0; i < 1001; i++ { for coun...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0717.1-bit-and-2-bit-Characters/717. 1-bit and 2-bit Characters_test.go
leetcode/0717.1-bit-and-2-bit-Characters/717. 1-bit and 2-bit Characters_test.go
package leetcode import ( "fmt" "testing" ) type question717 struct { para717 ans717 } // para 是参数 // one 代表第一个参数 type para717 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans717 struct { one bool } func Test_Problem717(t *testing.T) { qs := []question717{ { para717{[]int{1, 0, 0}}, ans717{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0717.1-bit-and-2-bit-Characters/717. 1-bit and 2-bit Characters.go
leetcode/0717.1-bit-and-2-bit-Characters/717. 1-bit and 2-bit Characters.go
package leetcode func isOneBitCharacter(bits []int) bool { var i int for i = 0; i < len(bits)-1; i++ { if bits[i] == 1 { i++ } } return i == len(bits)-1 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1736.Latest-Time-by-Replacing-Hidden-Digits/1736. Latest Time by Replacing Hidden Digits_test.go
leetcode/1736.Latest-Time-by-Replacing-Hidden-Digits/1736. Latest Time by Replacing Hidden Digits_test.go
package leetcode import ( "fmt" "testing" ) type question1736 struct { para1736 ans1736 } // para 是参数 // one 代表第一个参数 type para1736 struct { time string } // ans 是答案 // one 代表第一个答案 type ans1736 struct { one string } func Test_Problem1736(t *testing.T) { qs := []question1736{ { para1736{"2?:?0"}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1736.Latest-Time-by-Replacing-Hidden-Digits/1736. Latest Time by Replacing Hidden Digits.go
leetcode/1736.Latest-Time-by-Replacing-Hidden-Digits/1736. Latest Time by Replacing Hidden Digits.go
package leetcode func maximumTime(time string) string { timeb := []byte(time) if timeb[3] == '?' { timeb[3] = '5' } if timeb[4] == '?' { timeb[4] = '9' } if timeb[0] == '?' { if int(timeb[1]-'0') > 3 && int(timeb[1]-'0') < 10 { timeb[0] = '1' } else { timeb[0] = '2' } } if timeb[1] == '?' { t...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0979.Distribute-Coins-in-Binary-Tree/979. Distribute Coins in Binary Tree.go
leetcode/0979.Distribute-Coins-in-Binary-Tree/979. Distribute Coins in Binary Tree.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func distributeCoins(root *TreeNode) int { res :=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0979.Distribute-Coins-in-Binary-Tree/979. Distribute Coins in Binary Tree_test.go
leetcode/0979.Distribute-Coins-in-Binary-Tree/979. Distribute Coins in Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question979 struct { para979 ans979 } // para 是参数 // one 代表第一个参数 type para979 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans979 struct { one int } func Test_Problem979(t *testing.T) { qs := []question97...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false