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/0111.Minimum-Depth-of-Binary-Tree/111. Minimum Depth of Binary Tree.go
leetcode/0111.Minimum-Depth-of-Binary-Tree/111. Minimum Depth of Binary Tree.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func minDepth(root *TreeNode) int { if root == ni...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0111.Minimum-Depth-of-Binary-Tree/111. Minimum Depth of Binary Tree_test.go
leetcode/0111.Minimum-Depth-of-Binary-Tree/111. Minimum Depth of Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question111 struct { para111 ans111 } // para 是参数 // one 代表第一个参数 type para111 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans111 struct { one int } func Test_Problem111(t *testing.T) { qs := []question11...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0477.Total-Hamming-Distance/477. Total Hamming Distance.go
leetcode/0477.Total-Hamming-Distance/477. Total Hamming Distance.go
package leetcode func totalHammingDistance(nums []int) int { total, n := 0, len(nums) for i := 0; i < 32; i++ { bitCount := 0 for j := 0; j < n; j++ { bitCount += (nums[j] >> uint(i)) & 1 } total += bitCount * (n - bitCount) } return total } // 暴力解法超时! func totalHammingDistance1(nums []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/0477.Total-Hamming-Distance/477. Total Hamming Distance_test.go
leetcode/0477.Total-Hamming-Distance/477. Total Hamming Distance_test.go
package leetcode import ( "fmt" "testing" ) type question477 struct { para477 ans477 } // para 是参数 // one 代表第一个参数 type para477 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans477 struct { one int } func Test_Problem477(t *testing.T) { qs := []question477{ { para477{[]int{4, 14, 2}}, ans477{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0696.Count-Binary-Substrings/696. Count Binary Substrings.go
leetcode/0696.Count-Binary-Substrings/696. Count Binary Substrings.go
package leetcode func countBinarySubstrings(s string) int { last, res := 0, 0 for i := 0; i < len(s); { c, count := s[i], 1 for i++; i < len(s) && s[i] == c; i++ { count++ } res += min(count, last) last = count } return res } func min(a, b int) int { if a < b { return a } return b }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0696.Count-Binary-Substrings/696. Count Binary Substrings_test.go
leetcode/0696.Count-Binary-Substrings/696. Count Binary Substrings_test.go
package leetcode import ( "fmt" "testing" ) type question696 struct { para696 ans696 } // para 是参数 // one 代表第一个参数 type para696 struct { one string } // ans 是答案 // one 代表第一个答案 type ans696 struct { one int } func Test_Problem696(t *testing.T) { qs := []question696{ { para696{"00110011"}, ans696{6}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0598.Range-Addition-II/598. Range Addition II.go
leetcode/0598.Range-Addition-II/598. Range Addition II.go
package leetcode func maxCount(m int, n int, ops [][]int) int { minM, minN := m, n for _, op := range ops { minM = min(minM, op[0]) minN = min(minN, op[1]) } return minM * minN } func min(a, b int) int { if a < b { return a } return b }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0598.Range-Addition-II/598. Range Addition II_test.go
leetcode/0598.Range-Addition-II/598. Range Addition II_test.go
package leetcode import ( "fmt" "testing" ) type question598 struct { para598 ans598 } // para 是参数 // one 代表第一个参数 type para598 struct { m int n int ops [][]int } // ans 是答案 // one 代表第一个答案 type ans598 struct { one int } func Test_Problem598(t *testing.T) { qs := []question598{ { para598{3, 3, []...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0970.Powerful-Integers/970. Powerful Integers_test.go
leetcode/0970.Powerful-Integers/970. Powerful Integers_test.go
package leetcode import ( "fmt" "testing" ) type question970 struct { para970 ans970 } // para 是参数 // one 代表第一个参数 type para970 struct { one int two int b int } // ans 是答案 // one 代表第一个答案 type ans970 struct { one []int } func Test_Problem970(t *testing.T) { qs := []question970{ { para970{2, 3, 10},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0970.Powerful-Integers/970. Powerful Integers.go
leetcode/0970.Powerful-Integers/970. Powerful Integers.go
package leetcode import "math" func powerfulIntegers(x int, y int, bound int) []int { if x == 1 && y == 1 { if bound < 2 { return []int{} } return []int{2} } if x > y { x, y = y, x } visit, result := make(map[int]bool), make([]int, 0) for i := 0; ; i++ { found := false for j := 0; pow(x, i)+pow(y...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0400.Nth-Digit/400.Nth Digit.go
leetcode/0400.Nth-Digit/400.Nth Digit.go
package leetcode import "math" func findNthDigit(n int) int { if n <= 9 { return n } bits := 1 for n > 9*int(math.Pow10(bits-1))*bits { n -= 9 * int(math.Pow10(bits-1)) * bits bits++ } idx := n - 1 start := int(math.Pow10(bits - 1)) num := start + idx/bits digitIdx := idx % bits return num / int(math....
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0400.Nth-Digit/400.Nth Digit_test.go
leetcode/0400.Nth-Digit/400.Nth Digit_test.go
package leetcode import ( "fmt" "testing" ) type question400 struct { para400 ans400 } // para 是参数 type para400 struct { n int } // ans 是答案 type ans400 struct { ans int } func Test_Problem400(t *testing.T) { qs := []question400{ { para400{3}, ans400{3}, }, { para400{11}, ans400{0}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0498.Diagonal-Traverse/498. Diagonal Traverse_test.go
leetcode/0498.Diagonal-Traverse/498. Diagonal Traverse_test.go
package leetcode import ( "fmt" "testing" ) type question498 struct { para498 ans498 } // para 是参数 // one 代表第一个参数 type para498 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans498 struct { one []int } func Test_Problem498(t *testing.T) { qs := []question498{ { para498{[][]int{{3}, {2}, {9}}},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0498.Diagonal-Traverse/498. Diagonal Traverse.go
leetcode/0498.Diagonal-Traverse/498. Diagonal Traverse.go
package leetcode // 解法一 func findDiagonalOrder1(matrix [][]int) []int { if matrix == nil || len(matrix) == 0 || len(matrix[0]) == 0 { return nil } row, col, dir, i, x, y, d := len(matrix), len(matrix[0]), [2][2]int{ {-1, 1}, {1, -1}, }, 0, 0, 0, 0 total := row * col res := make([]int, total) for i < total...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers_test.go
leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers_test.go
package leetcode import ( "fmt" "testing" ) type question1655 struct { para1655 ans1655 } // para 是参数 // one 代表第一个参数 type para1655 struct { nums []int quantity []int } // ans 是答案 // one 代表第一个答案 type ans1655 struct { one bool } func Test_Problem1655(t *testing.T) { qs := []question1655{ { para165...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers.go
leetcode/1655.Distribute-Repeating-Integers/1655. Distribute Repeating Integers.go
package leetcode func canDistribute(nums []int, quantity []int) bool { freq := make(map[int]int) for _, n := range nums { freq[n]++ } return dfs(freq, quantity) } func dfs(freq map[int]int, quantity []int) bool { if len(quantity) == 0 { return true } visited := make(map[int]bool) for i := range freq { i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0015.3Sum/15. 3Sum_test.go
leetcode/0015.3Sum/15. 3Sum_test.go
package leetcode import ( "fmt" "testing" ) type question15 struct { para15 ans15 } // para 是参数 // one 代表第一个参数 type para15 struct { a []int } // ans 是答案 // one 代表第一个答案 type ans15 struct { one [][]int } func Test_Problem15(t *testing.T) { qs := []question15{ { para15{[]int{0, 0, 0}}, ans15{[][]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0015.3Sum/15. 3Sum.go
leetcode/0015.3Sum/15. 3Sum.go
package leetcode import ( "sort" ) // 解法一 最优解,双指针 + 排序 func threeSum(nums []int) [][]int { sort.Ints(nums) result, start, end, index, addNum, length := make([][]int, 0), 0, 0, 0, 0, len(nums) for index = 1; index < length-1; index++ { start, end = 0, length-1 if index > 1 && nums[index] == nums[index-1] { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/828. Count Unique Characters of All Substrings of a Given String.go
leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/828. Count Unique Characters of All Substrings of a Given String.go
package leetcode func uniqueLetterString(S string) int { res, left, right := 0, 0, 0 for i := 0; i < len(S); i++ { left = i - 1 for left >= 0 && S[left] != S[i] { left-- } right = i + 1 for right < len(S) && S[right] != S[i] { right++ } res += (i - left) * (right - i) } return res % 1000000007 ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/828. Count Unique Characters of All Substrings of a Given String_test.go
leetcode/0828.Count-Unique-Characters-of-All-Substrings-of-a-Given-String/828. Count Unique Characters of All Substrings of a Given String_test.go
package leetcode import ( "fmt" "testing" ) type question828 struct { para828 ans828 } // para 是参数 // one 代表第一个参数 type para828 struct { one string } // ans 是答案 // one 代表第一个答案 type ans828 struct { one int } func Test_Problem828(t *testing.T) { qs := []question828{ { para828{"BABABBABAA"}, ans828{35...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0084.Largest-Rectangle-in-Histogram/84. Largest Rectangle in Histogram_test.go
leetcode/0084.Largest-Rectangle-in-Histogram/84. Largest Rectangle in Histogram_test.go
package leetcode import ( "fmt" "testing" ) type question84 struct { para84 ans84 } // para 是参数 // one 代表第一个参数 type para84 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans84 struct { one int } func Test_Problem84(t *testing.T) { qs := []question84{ { para84{[]int{2, 1, 5, 6, 2, 3}}, ans84{1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0084.Largest-Rectangle-in-Histogram/84. Largest Rectangle in Histogram.go
leetcode/0084.Largest-Rectangle-in-Histogram/84. Largest Rectangle in Histogram.go
package leetcode func largestRectangleArea(heights []int) int { maxArea := 0 n := len(heights) + 2 // Add a sentry at the beginning and the end getHeight := func(i int) int { if i == 0 || n-1 == i { return 0 } return heights[i-1] } st := make([]int, 0, n/2) for i := 0; i < n; i++ { for len(st) > 0 &&...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0697.Degree-of-an-Array/697. Degree of an Array.go
leetcode/0697.Degree-of-an-Array/697. Degree of an Array.go
package leetcode func findShortestSubArray(nums []int) int { frequency, maxFreq, smallest := map[int][]int{}, 0, len(nums) for i, num := range nums { if _, found := frequency[num]; !found { frequency[num] = []int{1, i, i} } else { frequency[num][0]++ frequency[num][2] = i } if maxFreq < frequency[nu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0697.Degree-of-an-Array/697. Degree of an Array_test.go
leetcode/0697.Degree-of-an-Array/697. Degree of an Array_test.go
package leetcode import ( "fmt" "testing" ) type question697 struct { para697 ans697 } // para 是参数 // one 代表第一个参数 type para697 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans697 struct { one int } func Test_Problem697(t *testing.T) { qs := []question697{ { para697{[]int{1, 2, 2, 3, 1}}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0540.Single-Element-in-a-Sorted-Array/540.Single Element in a Sorted Array.go
leetcode/0540.Single-Element-in-a-Sorted-Array/540.Single Element in a Sorted Array.go
package leetcode func singleNonDuplicate(nums []int) int { left, right := 0, len(nums)-1 for left < right { mid := (left + right) / 2 if mid%2 == 0 { if nums[mid] == nums[mid+1] { left = mid + 1 } else { right = mid } } else { if nums[mid] == nums[mid-1] { left = mid + 1 } else { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0540.Single-Element-in-a-Sorted-Array/540.Single Element in a Sorted Array_test.go
leetcode/0540.Single-Element-in-a-Sorted-Array/540.Single Element in a Sorted Array_test.go
package leetcode import ( "fmt" "testing" ) type question540 struct { para540 ans540 } // para 是参数 type para540 struct { nums []int } // ans 是答案 type ans540 struct { ans int } func Test_Problem540(t *testing.T) { qs := []question540{ { para540{[]int{1, 1, 2, 3, 3, 4, 4, 8, 8}}, ans540{2}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1791.Find-Center-of-Star-Graph/1791.Find Center of Star Graph_test.go
leetcode/1791.Find-Center-of-Star-Graph/1791.Find Center of Star Graph_test.go
package leetcode import ( "fmt" "testing" ) type question1791 struct { para1791 ans1791 } // para 是参数 type para1791 struct { edges [][]int } // ans 是答案 type ans1791 struct { ans int } func Test_Problem1791(t *testing.T) { qs := []question1791{ { para1791{[][]int{{1, 2}, {2, 3}, {4, 2}}}, ans1791{2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1791.Find-Center-of-Star-Graph/1791.Find Center of Star Graph.go
leetcode/1791.Find-Center-of-Star-Graph/1791.Find Center of Star Graph.go
package leetcode func findCenter(edges [][]int) int { if edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1] { return edges[0][0] } return edges[0][1] }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0021.Merge-Two-Sorted-Lists/21. Merge Two Sorted Lists.go
leetcode/0021.Merge-Two-Sorted-Lists/21. Merge Two Sorted Lists.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 mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode { if l1 == nil {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0021.Merge-Two-Sorted-Lists/21. Merge Two Sorted Lists_test.go
leetcode/0021.Merge-Two-Sorted-Lists/21. Merge Two Sorted Lists_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question21 struct { para21 ans21 } // para 是参数 // one 代表第一个参数 type para21 struct { one []int another []int } // ans 是答案 // one 代表第一个答案 type ans21 struct { one []int } func Test_Problem21(t *testing.T) { qs ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks_test.go
leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks_test.go
package leetcode import ( "fmt" "testing" ) type question1665 struct { para1665 ans1665 } // para 是参数 // one 代表第一个参数 type para1665 struct { tasks [][]int } // ans 是答案 // one 代表第一个答案 type ans1665 struct { one int } func Test_Problem1665(t *testing.T) { qs := []question1665{ { para1665{[][]int{{1, 2}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks.go
leetcode/1665.Minimum-Initial-Energy-to-Finish-Tasks/1665. Minimum Initial Energy to Finish Tasks.go
package leetcode import ( "sort" ) func minimumEffort(tasks [][]int) int { sort.Sort(Task(tasks)) res, cur := 0, 0 for _, t := range tasks { if t[1] > cur { res += t[1] - cur cur = t[1] - t[0] } else { cur -= t[0] } } return res } func max(a, b int) int { if a > b { return a } return b } /...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0029.Divide-Two-Integers/29. Divide Two Integers.go
leetcode/0029.Divide-Two-Integers/29. Divide Two Integers.go
package leetcode import ( "math" ) // 解法一 递归版的二分搜索 func divide(dividend int, divisor int) int { sign, res := -1, 0 // low, high := 0, abs(dividend) if dividend == 0 { return 0 } if divisor == 1 { return dividend } if dividend == math.MinInt32 && divisor == -1 { return math.MaxInt32 } if dividend > 0 &...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0029.Divide-Two-Integers/29. Divide Two Integers_test.go
leetcode/0029.Divide-Two-Integers/29. Divide Two Integers_test.go
package leetcode import ( "fmt" "testing" ) type question29 struct { para29 ans29 } // para 是参数 // one 代表第一个参数 type para29 struct { dividend int divisor int } // ans 是答案 // one 代表第一个答案 type ans29 struct { one int } func Test_Problem29(t *testing.T) { qs := []question29{ { para29{10, 3}, ans29{3}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2166.Design-Bitset/2166. Design Bitset_test.go
leetcode/2166.Design-Bitset/2166. Design Bitset_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem2166(t *testing.T) { obj := Constructor(5) fmt.Printf("obj = %v\n", obj) obj.Fix(3) fmt.Printf("obj = %v\n", obj) obj.Fix(1) fmt.Printf("obj = %v\n", obj) obj.Flip() fmt.Printf("obj = %v\n", obj) fmt.Printf("all = %v\n", obj.All()) obj.Unfix(0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2166.Design-Bitset/2166. Design Bitset.go
leetcode/2166.Design-Bitset/2166. Design Bitset.go
package leetcode type Bitset struct { set []byte flipped []byte oneCount int size int } func Constructor(size int) Bitset { set := make([]byte, size) flipped := make([]byte, size) for i := 0; i < size; i++ { set[i] = byte('0') flipped[i] = byte('1') } return Bitset{ set: set, flipped: ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0949.Largest-Time-for-Given-Digits/949. Largest Time for Given Digits.go
leetcode/0949.Largest-Time-for-Given-Digits/949. Largest Time for Given Digits.go
package leetcode import "fmt" func largestTimeFromDigits(A []int) string { flag, res := false, 0 for i := 0; i < 4; i++ { for j := 0; j < 4; j++ { if i == j { continue } for k := 0; k < 4; k++ { if i == k || j == k { continue } l := 6 - i - j - k hour := A[i]*10 + A[j] min :=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0949.Largest-Time-for-Given-Digits/949. Largest Time for Given Digits_test.go
leetcode/0949.Largest-Time-for-Given-Digits/949. Largest Time for Given Digits_test.go
package leetcode import ( "fmt" "testing" ) type question949 struct { para949 ans949 } // para 是参数 // one 代表第一个参数 type para949 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans949 struct { one string } func Test_Problem949(t *testing.T) { qs := []question949{ { para949{[]int{1, 2, 3, 4}}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0771.Jewels-and-Stones/771. Jewels and Stones_test.go
leetcode/0771.Jewels-and-Stones/771. Jewels and Stones_test.go
package leetcode import ( "fmt" "testing" ) type question771 struct { para771 ans771 } // para 是参数 // one 代表第一个参数 type para771 struct { one string two string } // ans 是答案 // one 代表第一个答案 type ans771 struct { one int } func Test_Problem771(t *testing.T) { qs := []question771{ { para771{"aA", "aAAbbbb"}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0771.Jewels-and-Stones/771. Jewels and Stones.go
leetcode/0771.Jewels-and-Stones/771. Jewels and Stones.go
package leetcode import "strings" // 解法一 func numJewelsInStones(J string, S string) int { count := 0 for i := range S { if strings.Contains(J, string(S[i])) { count++ } } return count } // 解法二 func numJewelsInStones1(J string, S string) int { cache, result := make(map[rune]bool), 0 for _, r := range J {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0792.Number-of-Matching-Subsequences/792. Number of Matching Subsequences_test.go
leetcode/0792.Number-of-Matching-Subsequences/792. Number of Matching Subsequences_test.go
package leetcode import ( "fmt" "testing" ) type question792 struct { para792 ans792 } // para 是参数 // one 代表第一个参数 type para792 struct { s string words []string } // ans 是答案 // one 代表第一个答案 type ans792 struct { one int } func Test_Problem792(t *testing.T) { qs := []question792{ { para792{"abcde", ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0792.Number-of-Matching-Subsequences/792. Number of Matching Subsequences.go
leetcode/0792.Number-of-Matching-Subsequences/792. Number of Matching Subsequences.go
package leetcode func numMatchingSubseq(s string, words []string) int { hash, res := make([][]string, 26), 0 for _, w := range words { hash[int(w[0]-'a')] = append(hash[int(w[0]-'a')], w) } for _, c := range s { words := hash[int(byte(c)-'a')] hash[int(byte(c)-'a')] = []string{} for _, w := range words { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0667.Beautiful-Arrangement-II/667. Beautiful Arrangement II.go
leetcode/0667.Beautiful-Arrangement-II/667. Beautiful Arrangement II.go
package leetcode func constructArray(n int, k int) []int { res := []int{} for i := 0; i < n-k-1; i++ { res = append(res, i+1) } for i := n - k; i < n-k+(k+1)/2; i++ { res = append(res, i) res = append(res, 2*n-k-i) } if k%2 == 0 { res = append(res, n-k+(k+1)/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/0667.Beautiful-Arrangement-II/667. Beautiful Arrangement II_test.go
leetcode/0667.Beautiful-Arrangement-II/667. Beautiful Arrangement II_test.go
package leetcode import ( "fmt" "testing" ) type question667 struct { para667 ans667 } // para 是参数 // one 代表第一个参数 type para667 struct { n int k int } // ans 是答案 // one 代表第一个答案 type ans667 struct { one []int } func Test_Problem667(t *testing.T) { qs := []question667{ { para667{3, 1}, ans667{[]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0817.Linked-List-Components/817. Linked List Components.go
leetcode/0817.Linked-List-Components/817. Linked List Components.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 numComponents(head *ListNode, G []int) int { if head.Next == nil { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0817.Linked-List-Components/817. Linked List Components_test.go
leetcode/0817.Linked-List-Components/817. Linked List Components_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question817 struct { para817 ans817 } // para 是参数 // one 代表第一个参数 type para817 struct { one []int another []int } // ans 是答案 // one 代表第一个答案 type ans817 struct { one int } func Test_Problem817(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/0319.Bulb-Switcher/319.Bulb Switcher.go
leetcode/0319.Bulb-Switcher/319.Bulb Switcher.go
package leetcode import "math" func bulbSwitch(n int) int { return int(math.Sqrt(float64(n))) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0319.Bulb-Switcher/319.Bulb Switcher_test.go
leetcode/0319.Bulb-Switcher/319.Bulb Switcher_test.go
package leetcode import ( "fmt" "testing" ) type question319 struct { para319 ans319 } // para 是参数 type para319 struct { n int } // ans 是答案 type ans319 struct { ans int } func Test_Problem319(t *testing.T) { qs := []question319{ { para319{3}, ans319{1}, }, { para319{0}, ans319{0}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0810.Chalkboard-XOR-Game/810. Chalkboard XOR Game_test.go
leetcode/0810.Chalkboard-XOR-Game/810. Chalkboard XOR Game_test.go
package leetcode import ( "fmt" "testing" ) type question810 struct { para810 ans810 } // para 是参数 // one 代表第一个参数 type para810 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans810 struct { one bool } func Test_Problem810(t *testing.T) { qs := []question810{ { para810{[]int{1, 1, 2}}, ans810...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0810.Chalkboard-XOR-Game/810. Chalkboard XOR Game.go
leetcode/0810.Chalkboard-XOR-Game/810. Chalkboard XOR Game.go
package leetcode func xorGame(nums []int) bool { if len(nums)%2 == 0 { return true } xor := 0 for _, num := range nums { xor ^= num } return xor == 0 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1299.Replace-Elements-with-Greatest-Element-on-Right-Side/1299. Replace Elements with Greatest Element on Right Side_test.go
leetcode/1299.Replace-Elements-with-Greatest-Element-on-Right-Side/1299. Replace Elements with Greatest Element on Right Side_test.go
package leetcode import ( "fmt" "testing" ) type question1299 struct { para1299 ans1299 } // para 是参数 // one 代表第一个参数 type para1299 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1299 struct { one []int } func Test_Problem1299(t *testing.T) { qs := []question1299{ { para1299{[]int{17, 18, 5, 4...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1299.Replace-Elements-with-Greatest-Element-on-Right-Side/1299. Replace Elements with Greatest Element on Right Side.go
leetcode/1299.Replace-Elements-with-Greatest-Element-on-Right-Side/1299. Replace Elements with Greatest Element on Right Side.go
package leetcode func replaceElements(arr []int) []int { j, temp := -1, 0 for i := len(arr) - 1; i >= 0; i-- { temp = arr[i] arr[i] = j j = max(j, temp) } return arr } func max(a int, b int) int { if a > b { return a } return b }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2043.Simple-Bank-System/2043.Simple Bank System_test.go
leetcode/2043.Simple-Bank-System/2043.Simple Bank System_test.go
package leetcode import ( "fmt" "testing" ) type question2043 struct { para2043 ans2043 } // para 是参数 type para2043 struct { ops []string para [][]int64 } // ans 是答案 type ans2043 struct { ans []bool } func Test_Problem2043(t *testing.T) { qs := []question2043{ { para2043{ []string{"Bank", "with...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2043.Simple-Bank-System/2043.Simple Bank System.go
leetcode/2043.Simple-Bank-System/2043.Simple Bank System.go
package leetcode type Bank struct { accounts []int64 n int } func Constructor(balance []int64) Bank { return Bank{ accounts: balance, n: len(balance), } } func (this *Bank) Transfer(account1 int, account2 int, money int64) bool { if account1 > this.n || account2 > this.n { return false } i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1249.Minimum-Remove-to-Make-Valid-Parentheses/1249. Minimum Remove to Make Valid Parentheses.go
leetcode/1249.Minimum-Remove-to-Make-Valid-Parentheses/1249. Minimum Remove to Make Valid Parentheses.go
package leetcode func minRemoveToMakeValid(s string) string { res, opens := []byte{}, 0 for i := 0; i < len(s); i++ { if s[i] == '(' { opens++ } else if s[i] == ')' { if opens == 0 { continue } opens-- } res = append(res, s[i]) } for i := len(res) - 1; i >= 0; i-- { if res[i] == '(' && op...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1249.Minimum-Remove-to-Make-Valid-Parentheses/1249. Minimum Remove to Make Valid Parentheses_test.go
leetcode/1249.Minimum-Remove-to-Make-Valid-Parentheses/1249. Minimum Remove to Make Valid Parentheses_test.go
package leetcode import ( "fmt" "testing" ) type question1249 struct { para1249 ans1249 } // para 是参数 // one 代表第一个参数 type para1249 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1249 struct { one string } func Test_Problem1249(t *testing.T) { qs := []question1249{ { para1249{"lee(t(c)o)de)"}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1175.Prime-Arrangements/1175. Prime Arrangements.go
leetcode/1175.Prime-Arrangements/1175. Prime Arrangements.go
package leetcode import "sort" var primes = []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97} func numPrimeArrangements(n int) int { primeCount := sort.Search(25, func(i int) bool { return primes[i] > n }) return factorial(primeCount) * factorial(n-primeCount) % ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1175.Prime-Arrangements/1175. Prime Arrangements_test.go
leetcode/1175.Prime-Arrangements/1175. Prime Arrangements_test.go
package leetcode import ( "fmt" "testing" ) type question1175 struct { para1175 ans1175 } // para 是参数 // one 代表第一个参数 type para1175 struct { one int } // ans 是答案 // one 代表第一个答案 type ans1175 struct { one int } func Test_Problem1175(t *testing.T) { qs := []question1175{ { para1175{5}, ans1175{12}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0011.Container-With-Most-Water/11. Container With Most Water.go
leetcode/0011.Container-With-Most-Water/11. Container With Most Water.go
package leetcode func maxArea(height []int) int { max, start, end := 0, 0, len(height)-1 for start < end { width := end - start high := 0 if height[start] < height[end] { high = height[start] start++ } else { high = height[end] end-- } temp := width * high if temp > max { max = temp }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0011.Container-With-Most-Water/11. Container With Most Water_test.go
leetcode/0011.Container-With-Most-Water/11. Container With Most Water_test.go
package leetcode import ( "fmt" "testing" ) type question11 struct { para11 ans11 } // para 是参数 // one 代表第一个参数 type para11 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans11 struct { one int } func Test_Problem11(t *testing.T) { qs := []question11{ { para11{[]int{1, 8, 6, 2, 5, 4, 8, 3, 7}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence.go
leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence.go
package leetcode // 单调栈 func mostCompetitive(nums []int, k int) []int { stack := make([]int, 0, len(nums)) for i := 0; i < len(nums); i++ { for len(stack)+len(nums)-i > k && len(stack) > 0 && nums[i] < stack[len(stack)-1] { stack = stack[:len(stack)-1] } stack = append(stack, nums[i]) } return stack[:k] }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence_test.go
leetcode/1673.Find-the-Most-Competitive-Subsequence/1673. Find the Most Competitive Subsequence_test.go
package leetcode import ( "fmt" "testing" ) type question1673 struct { para1673 ans1673 } // para 是参数 // one 代表第一个参数 type para1673 struct { nums []int k int } // ans 是答案 // one 代表第一个答案 type ans1673 struct { one []int } func Test_Problem1673(t *testing.T) { qs := []question1673{ { para1673{[]int{3...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0059.Spiral-Matrix-II/59. Spiral Matrix II_test.go
leetcode/0059.Spiral-Matrix-II/59. Spiral Matrix II_test.go
package leetcode import ( "fmt" "testing" ) type question59 struct { para59 ans59 } // para 是参数 // one 代表第一个参数 type para59 struct { one int } // ans 是答案 // one 代表第一个答案 type ans59 struct { one [][]int } func Test_Problem59(t *testing.T) { qs := []question59{ { para59{3}, ans59{[][]int{{1, 2, 3}, {8...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0059.Spiral-Matrix-II/59. Spiral Matrix II.go
leetcode/0059.Spiral-Matrix-II/59. Spiral Matrix II.go
package leetcode func generateMatrix(n int) [][]int { if n == 0 { return [][]int{} } if n == 1 { return [][]int{{1}} } res, visit, round, x, y, spDir := make([][]int, n), make([][]int, n), 0, 0, 0, [][]int{ {0, 1}, // 朝右 {1, 0}, // 朝下 {0, -1}, // 朝左 {-1, 0}, // 朝上 } for i := 0; i < n; i++ { visi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0572.Subtree-of-Another-Tree/572. Subtree of Another Tree.go
leetcode/0572.Subtree-of-Another-Tree/572. Subtree of Another 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 isSubtree(s *TreeNode, t *TreeNode) bool { i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0572.Subtree-of-Another-Tree/572. Subtree of Another Tree_test.go
leetcode/0572.Subtree-of-Another-Tree/572. Subtree of Another Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question572 struct { para572 ans572 } // para 是参数 // one 代表第一个参数 type para572 struct { s []int t []int } // ans 是答案 // one 代表第一个答案 type ans572 struct { one bool } func Test_Problem572(t *testing.T) { qs := []qu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1818.Minimum-Absolute-Sum-Difference/1818. Minimum Absolute Sum Difference_test.go
leetcode/1818.Minimum-Absolute-Sum-Difference/1818. Minimum Absolute Sum Difference_test.go
package leetcode import ( "fmt" "testing" ) type question1818 struct { para1818 ans1818 } // para 是参数 // one 代表第一个参数 type para1818 struct { nums1 []int nums2 []int } // ans 是答案 // one 代表第一个答案 type ans1818 struct { one int } func Test_Problem1818(t *testing.T) { qs := []question1818{ { para1818{[]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1818.Minimum-Absolute-Sum-Difference/1818. Minimum Absolute Sum Difference.go
leetcode/1818.Minimum-Absolute-Sum-Difference/1818. Minimum Absolute Sum Difference.go
package leetcode func minAbsoluteSumDiff(nums1 []int, nums2 []int) int { diff := 0 maxDiff := 0 for i, n2 := range nums2 { d := abs(nums1[i] - n2) diff += d if maxDiff < d { t := 100001 for _, n1 := range nums1 { maxDiff = max(maxDiff, d-min(t, abs(n1-n2))) } } } return (diff - maxDiff) % (1e...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0148.Sort-List/148. Sort List.go
leetcode/0148.Sort-List/148. Sort List.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // ListNode define type ListNode = structures.ListNode /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func sortList(head *ListNode) *ListNode { length := 0 cur := head for c...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0148.Sort-List/148. Sort List_test.go
leetcode/0148.Sort-List/148. Sort List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question148 struct { para148 ans148 } // para 是参数 // one 代表第一个参数 type para148 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans148 struct { one []int } func Test_Problem148(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/0108.Convert-Sorted-Array-to-Binary-Search-Tree/108. Convert Sorted Array to Binary Search Tree.go
leetcode/0108.Convert-Sorted-Array-to-Binary-Search-Tree/108. Convert Sorted Array to Binary Search Tree.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func sortedArrayToBST(nums []int) *TreeNode { if ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0108.Convert-Sorted-Array-to-Binary-Search-Tree/108. Convert Sorted Array to Binary Search Tree_test.go
leetcode/0108.Convert-Sorted-Array-to-Binary-Search-Tree/108. Convert Sorted Array to Binary Search Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question108 struct { para108 ans108 } // para 是参数 // one 代表第一个参数 type para108 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans108 struct { one []int } func Test_Problem108(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/1389.Create-Target-Array-in-the-Given-Order/1389. Create Target Array in the Given Order.go
leetcode/1389.Create-Target-Array-in-the-Given-Order/1389. Create Target Array in the Given Order.go
package leetcode func createTargetArray(nums []int, index []int) []int { result := make([]int, len(nums)) for i, pos := range index { copy(result[pos+1:i+1], result[pos:i]) result[pos] = nums[i] } return result }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1389.Create-Target-Array-in-the-Given-Order/1389. Create Target Array in the Given Order_test.go
leetcode/1389.Create-Target-Array-in-the-Given-Order/1389. Create Target Array in the Given Order_test.go
package leetcode import ( "fmt" "testing" ) type question1389 struct { para1389 ans1389 } // para 是参数 // one 代表第一个参数 type para1389 struct { nums []int index []int } // ans 是答案 // one 代表第一个答案 type ans1389 struct { one []int } func Test_Problem1389(t *testing.T) { qs := []question1389{ { para1389{[]i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0497.Random-Point-in-Non-overlapping-Rectangles/497. Random Point in Non-overlapping Rectangles.go
leetcode/0497.Random-Point-in-Non-overlapping-Rectangles/497. Random Point in Non-overlapping Rectangles.go
package leetcode import "math/rand" // Solution497 define type Solution497 struct { rects [][]int arr []int } // Constructor497 define func Constructor497(rects [][]int) Solution497 { s := Solution497{ rects: rects, arr: make([]int, len(rects)), } for i := 0; i < len(rects); i++ { area := (rects[i][2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0497.Random-Point-in-Non-overlapping-Rectangles/497. Random Point in Non-overlapping Rectangles_test.go
leetcode/0497.Random-Point-in-Non-overlapping-Rectangles/497. Random Point in Non-overlapping Rectangles_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem497(t *testing.T) { w := [][]int{{1, 1, 5, 5}} sol := Constructor497(w) fmt.Printf("1.Pick = %v\n", sol.Pick()) fmt.Printf("2.Pick = %v\n", sol.Pick()) fmt.Printf("3.Pick = %v\n", sol.Pick()) fmt.Printf("4.Pick = %v\n", sol.Pick()) fmt.Printf("5.Pi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0130.Surrounded-Regions/130. Surrounded Regions.go
leetcode/0130.Surrounded-Regions/130. Surrounded Regions.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } // 解法一 并查集 func solve(board [][]byte) { if len(board) == 0 { return } m, n := len(board[0]), len(board) uf := template.UnionFind{} uf.Init(n*m + 1) // 特意多一个特殊点用来标记 for i := 0; i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0130.Surrounded-Regions/130. Surrounded Regions_test.go
leetcode/0130.Surrounded-Regions/130. Surrounded Regions_test.go
package leetcode import ( "fmt" "testing" ) type question130 struct { para130 ans130 } // para 是参数 // one 代表第一个参数 type para130 struct { one [][]byte } // ans 是答案 // one 代表第一个答案 type ans130 struct { one [][]byte } func Test_Problem130(t *testing.T) { qs := []question130{ { para130{[][]byte{}}, ans1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1019.Next-Greater-Node-In-Linked-List/1019. Next Greater Node In Linked List_test.go
leetcode/1019.Next-Greater-Node-In-Linked-List/1019. Next Greater Node In Linked List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1019 struct { para1019 ans1019 } // para 是参数 // one 代表第一个参数 type para1019 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1019 struct { one []int } func Test_Problem1019(t *testing.T) { qs := []qu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1019.Next-Greater-Node-In-Linked-List/1019. Next Greater Node In Linked List.go
leetcode/1019.Next-Greater-Node-In-Linked-List/1019. Next Greater Node In Linked List.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // ListNode define type ListNode = structures.ListNode /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ // 解法一 单调栈 func nextLargerNodes(head *ListNode) []int { type node struct...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990085.Maximal-Rectangle/85. Maximal Rectangle.go
leetcode/9990085.Maximal-Rectangle/85. Maximal Rectangle.go
package leetcode func maximalRectangle(matrix [][]byte) int { return 0 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990085.Maximal-Rectangle/85. Maximal Rectangle_test.go
leetcode/9990085.Maximal-Rectangle/85. Maximal Rectangle_test.go
package leetcode import ( "fmt" "testing" ) type question85 struct { para85 ans85 } // para 是参数 // one 代表第一个参数 type para85 struct { one [][]byte } // ans 是答案 // one 代表第一个答案 type ans85 struct { one int } func Test_Problem85(t *testing.T) { qs := []question85{ { para85{[][]byte{{'1', '0', '1', '0', '0'...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0020.Valid-Parentheses/20. Valid Parentheses.go
leetcode/0020.Valid-Parentheses/20. Valid Parentheses.go
package leetcode func isValid(s string) bool { // 空字符串直接返回 true if len(s) == 0 { return true } stack := make([]rune, 0) for _, v := range s { if (v == '[') || (v == '(') || (v == '{') { stack = append(stack, v) } else if ((v == ']') && len(stack) > 0 && stack[len(stack)-1] == '[') || ((v == ')') && le...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0020.Valid-Parentheses/20. Valid Parentheses_test.go
leetcode/0020.Valid-Parentheses/20. Valid Parentheses_test.go
package leetcode import ( "fmt" "testing" ) type question20 struct { para20 ans20 } // para 是参数 // one 代表第一个参数 type para20 struct { one string } // ans 是答案 // one 代表第一个答案 type ans20 struct { one bool } func Test_Problem20(t *testing.T) { qs := []question20{ { para20{"()[]{}"}, ans20{true}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0946.Validate-Stack-Sequences/946. Validate Stack Sequences.go
leetcode/0946.Validate-Stack-Sequences/946. Validate Stack Sequences.go
package leetcode func validateStackSequences(pushed []int, popped []int) bool { stack, j, N := []int{}, 0, len(pushed) for _, x := range pushed { stack = append(stack, x) for len(stack) != 0 && j < N && stack[len(stack)-1] == popped[j] { stack = stack[0 : len(stack)-1] j++ } } return j == N }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0946.Validate-Stack-Sequences/946. Validate Stack Sequences_test.go
leetcode/0946.Validate-Stack-Sequences/946. Validate Stack Sequences_test.go
package leetcode import ( "fmt" "testing" ) type question946 struct { para946 ans946 } // para 是参数 // one 代表第一个参数 type para946 struct { one []int two []int } // ans 是答案 // one 代表第一个答案 type ans946 struct { one bool } func Test_Problem946(t *testing.T) { qs := []question946{ { para946{[]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/0752.Open-the-Lock/752. Open the Lock.go
leetcode/0752.Open-the-Lock/752. Open the Lock.go
package leetcode func openLock(deadends []string, target string) int { if target == "0000" { return 0 } targetNum, visited := strToInt(target), make([]bool, 10000) visited[0] = true for _, deadend := range deadends { num := strToInt(deadend) if num == 0 { return -1 } visited[num] = true } depth, cu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0752.Open-the-Lock/752. Open the Lock_test.go
leetcode/0752.Open-the-Lock/752. Open the Lock_test.go
package leetcode import ( "fmt" "testing" ) type question752 struct { para752 ans752 } // para 是参数 // one 代表第一个参数 type para752 struct { deadends []string target string } // ans 是答案 // one 代表第一个答案 type ans752 struct { one int } func Test_Problem752(t *testing.T) { qs := []question752{ { para752{[]s...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990363.Max-Sum-of-Rectangle-No-Larger-Than-K/363. Max Sum of Rectangle No Larger Than K_test.go
leetcode/9990363.Max-Sum-of-Rectangle-No-Larger-Than-K/363. Max Sum of Rectangle No Larger Than K_test.go
package leetcode import ( "fmt" "testing" ) type question363 struct { para363 ans363 } // para 是参数 // one 代表第一个参数 type para363 struct { one [][]int k int } // ans 是答案 // one 代表第一个答案 type ans363 struct { one int } func Test_Problem363(t *testing.T) { qs := []question363{ { para363{[][]int{{1, 0, 1}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990363.Max-Sum-of-Rectangle-No-Larger-Than-K/363. Max Sum of Rectangle No Larger Than K.go
leetcode/9990363.Max-Sum-of-Rectangle-No-Larger-Than-K/363. Max Sum of Rectangle No Larger Than K.go
package leetcode import ( "math" ) // 解法一 二分搜索 func maxSumSubmatrix(matrix [][]int, k int) int { // 转换为前缀和 for i := 0; i < len(matrix); i++ { for j := 1; j < len(matrix[0]); j++ { matrix[i][j] += matrix[i][j-1] } } sum, absMax, absMaxFound := make([]int, len(matrix)), 0, false for y1 := 0; y1 < len(matri...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0995.Minimum-Number-of-K-Consecutive-Bit-Flips/995. Minimum Number of K Consecutive Bit Flips_test.go
leetcode/0995.Minimum-Number-of-K-Consecutive-Bit-Flips/995. Minimum Number of K Consecutive Bit Flips_test.go
package leetcode import ( "fmt" "testing" ) type question995 struct { para995 ans995 } // para 是参数 // one 代表第一个参数 type para995 struct { one []int k int } // ans 是答案 // one 代表第一个答案 type ans995 struct { one int } func Test_Problem995(t *testing.T) { qs := []question995{ { para995{[]int{0, 1, 0}, 1},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0995.Minimum-Number-of-K-Consecutive-Bit-Flips/995. Minimum Number of K Consecutive Bit Flips.go
leetcode/0995.Minimum-Number-of-K-Consecutive-Bit-Flips/995. Minimum Number of K Consecutive Bit Flips.go
package leetcode func minKBitFlips(A []int, K int) int { flippedTime, count := 0, 0 for i := 0; i < len(A); i++ { if i >= K && A[i-K] == 2 { flippedTime-- } // 下面这个判断包含了两种情况: // 如果 flippedTime 是奇数,且 A[i] == 1 就需要翻转 // 如果 flippedTime 是偶数,且 A[i] == 0 就需要翻转 if flippedTime%2 == A[i] { if i+K > len(A) {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1145.Binary-Tree-Coloring-Game/1145. Binary Tree Coloring Game.go
leetcode/1145.Binary-Tree-Coloring-Game/1145. Binary Tree Coloring Game.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 btreeGameWinningMove(root *TreeNode, n int, x...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1145.Binary-Tree-Coloring-Game/1145. Binary Tree Coloring Game_test.go
leetcode/1145.Binary-Tree-Coloring-Game/1145. Binary Tree Coloring Game_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1145 struct { para1145 ans1145 } // para 是参数 // one 代表第一个参数 type para1145 struct { root []int n int x int } // ans 是答案 // one 代表第一个答案 type ans1145 struct { one bool } func Test_Problem1145(t *testi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0819.Most-Common-Word/819. Most Common Word.go
leetcode/0819.Most-Common-Word/819. Most Common Word.go
package leetcode import "strings" func mostCommonWord(paragraph string, banned []string) string { freqMap, start := make(map[string]int), -1 for i, c := range paragraph { if c == ' ' || c == '!' || c == '?' || c == '\'' || c == ',' || c == ';' || c == '.' { if start > -1 { word := strings.ToLower(paragraph...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0819.Most-Common-Word/819. Most Common Word_test.go
leetcode/0819.Most-Common-Word/819. Most Common Word_test.go
package leetcode import ( "fmt" "testing" ) type question819 struct { para819 ans819 } // para 是参数 // one 代表第一个参数 type para819 struct { one string b []string } // ans 是答案 // one 代表第一个答案 type ans819 struct { one string } func Test_Problem819(t *testing.T) { qs := []question819{ { para819{"Bob hit a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0474.Ones-and-Zeroes/474. Ones and Zeroes.go
leetcode/0474.Ones-and-Zeroes/474. Ones and Zeroes.go
package leetcode import "strings" func findMaxForm(strs []string, m int, n int) int { dp := make([][]int, m+1) for i := 0; i < m+1; i++ { dp[i] = make([]int, n+1) } for _, s := range strs { zero := strings.Count(s, "0") one := len(s) - zero if zero > m || one > n { continue } for i := m; i >= zero;...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0474.Ones-and-Zeroes/474. Ones and Zeroes_test.go
leetcode/0474.Ones-and-Zeroes/474. Ones and Zeroes_test.go
package leetcode import ( "fmt" "testing" ) type question474 struct { para474 ans474 } // para 是参数 // one 代表第一个参数 type para474 struct { strs []string m int n int } // ans 是答案 // one 代表第一个答案 type ans474 struct { one int } func Test_Problem474(t *testing.T) { qs := []question474{ { para474{[]st...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1295.Find-Numbers-with-Even-Number-of-Digits/1295. Find Numbers with Even Number of Digits_test.go
leetcode/1295.Find-Numbers-with-Even-Number-of-Digits/1295. Find Numbers with Even Number of Digits_test.go
package leetcode import ( "fmt" "testing" ) type question1295 struct { para1295 ans1295 } // para 是参数 // one 代表第一个参数 type para1295 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1295 struct { one int } func Test_Problem1295(t *testing.T) { qs := []question1295{ { para1295{[]int{12, 345, 2, 6,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1295.Find-Numbers-with-Even-Number-of-Digits/1295. Find Numbers with Even Number of Digits.go
leetcode/1295.Find-Numbers-with-Even-Number-of-Digits/1295. Find Numbers with Even Number of Digits.go
package leetcode import "strconv" func findNumbers(nums []int) int { res := 0 for _, n := range nums { res += 1 - len(strconv.Itoa(n))%2 } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false