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/0914.X-of-a-Kind-in-a-Deck-of-Cards/914. X of a Kind in a Deck of Cards.go
leetcode/0914.X-of-a-Kind-in-a-Deck-of-Cards/914. X of a Kind in a Deck of Cards.go
package leetcode func hasGroupsSizeX(deck []int) bool { if len(deck) < 2 { return false } m, g := map[int]int{}, -1 for _, d := range deck { m[d]++ } for _, v := range m { if g == -1 { g = v } else { g = gcd(g, v) } } return g >= 2 } func gcd(a, b int) int { if a == 0 { return b } return ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0914.X-of-a-Kind-in-a-Deck-of-Cards/914. X of a Kind in a Deck of Cards_test.go
leetcode/0914.X-of-a-Kind-in-a-Deck-of-Cards/914. X of a Kind in a Deck of Cards_test.go
package leetcode import ( "fmt" "testing" ) type question914 struct { para914 ans914 } // para 是参数 // one 代表第一个参数 type para914 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans914 struct { one bool } func Test_Problem914(t *testing.T) { qs := []question914{ { para914{[]int{1, 2, 3, 4, 4, 3, 2, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0306.Additive-Number/306. Additive Number.go
leetcode/0306.Additive-Number/306. Additive Number.go
package leetcode import ( "strconv" "strings" ) // This function controls various combinations as starting points func isAdditiveNumber(num string) bool { if len(num) < 3 { return false } for firstEnd := 0; firstEnd < len(num)/2; firstEnd++ { if num[0] == '0' && firstEnd > 0 { break } first, _ := strc...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0306.Additive-Number/306. Additive Number_test.go
leetcode/0306.Additive-Number/306. Additive Number_test.go
package leetcode import ( "fmt" "testing" ) type question306 struct { para306 ans306 } // para 是参数 // one 代表第一个参数 type para306 struct { one string } // ans 是答案 // one 代表第一个答案 type ans306 struct { one bool } func Test_Problem306(t *testing.T) { qs := []question306{ { para306{"112358"}, ans306{true}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0812.Largest-Triangle-Area/812. Largest Triangle Area.go
leetcode/0812.Largest-Triangle-Area/812. Largest Triangle Area.go
package leetcode func largestTriangleArea(points [][]int) float64 { maxArea, n := 0.0, len(points) for i := 0; i < n; i++ { for j := i + 1; j < n; j++ { for k := j + 1; k < n; k++ { maxArea = max(maxArea, area(points[i], points[j], points[k])) } } } return maxArea } func area(p1, p2, p3 []int) float...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0812.Largest-Triangle-Area/812. Largest Triangle Area_test.go
leetcode/0812.Largest-Triangle-Area/812. Largest Triangle Area_test.go
package leetcode import ( "fmt" "testing" ) type question812 struct { para812 ans812 } // para 是参数 // one 代表第一个参数 type para812 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans812 struct { one float64 } func Test_Problem812(t *testing.T) { qs := []question812{ { para812{[][]int{{0, 0}, {0, 1}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0347.Top-K-Frequent-Elements/347. Top K Frequent Elements.go
leetcode/0347.Top-K-Frequent-Elements/347. Top K Frequent Elements.go
package leetcode import "container/heap" func topKFrequent(nums []int, k int) []int { m := make(map[int]int) for _, n := range nums { m[n]++ } q := PriorityQueue{} for key, count := range m { heap.Push(&q, &Item{key: key, count: count}) } var result []int for len(result) < k { item := heap.Pop(&q).(*Ite...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0347.Top-K-Frequent-Elements/347. Top K Frequent Elements_test.go
leetcode/0347.Top-K-Frequent-Elements/347. Top K Frequent Elements_test.go
package leetcode import ( "fmt" "testing" ) type question347 struct { para347 ans347 } // para 是参数 // one 代表第一个参数 type para347 struct { one []int two int } // ans 是答案 // one 代表第一个答案 type ans347 struct { one []int } func Test_Problem347(t *testing.T) { qs := []question347{ { para347{[]int{1, 1, 1, 2,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0462.Minimum-Moves-to-Equal-Array-Elements-II/462. Minimum Moves to Equal Array Elements II_test.go
leetcode/0462.Minimum-Moves-to-Equal-Array-Elements-II/462. Minimum Moves to Equal Array Elements II_test.go
package leetcode import ( "fmt" "testing" ) type question462 struct { para462 ans462 } // para 是参数 // one 代表第一个参数 type para462 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans462 struct { one int } func Test_Problem462(t *testing.T) { qs := []question462{ { para462{[]int{}}, ans462{0}, }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0462.Minimum-Moves-to-Equal-Array-Elements-II/462. Minimum Moves to Equal Array Elements II.go
leetcode/0462.Minimum-Moves-to-Equal-Array-Elements-II/462. Minimum Moves to Equal Array Elements II.go
package leetcode import ( "math" "sort" ) func minMoves2(nums []int) int { if len(nums) == 0 { return 0 } moves, mid := 0, len(nums)/2 sort.Ints(nums) for i := range nums { if i == mid { continue } moves += int(math.Abs(float64(nums[mid] - nums[i]))) } return moves }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1877.Minimize-Maximum-Pair-Sum-in-Array/1877. Minimize Maximum Pair Sum in Array.go
leetcode/1877.Minimize-Maximum-Pair-Sum-in-Array/1877. Minimize Maximum Pair Sum in Array.go
package leetcode import "sort" func minPairSum(nums []int) int { sort.Ints(nums) n, res := len(nums), 0 for i, val := range nums[:n/2] { res = max(res, val+nums[n-1-i]) } 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/1877.Minimize-Maximum-Pair-Sum-in-Array/1877. Minimize Maximum Pair Sum in Array_test.go
leetcode/1877.Minimize-Maximum-Pair-Sum-in-Array/1877. Minimize Maximum Pair Sum in Array_test.go
package leetcode import ( "fmt" "testing" ) type question1877 struct { para1877 ans1877 } // para 是参数 // one 代表第一个参数 type para1877 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1877 struct { one int } func Test_Problem1877(t *testing.T) { qs := []question1877{ { para1877{[]int{2, 2, 1, 2, 1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0826.Most-Profit-Assigning-Work/826. Most Profit Assigning Work_test.go
leetcode/0826.Most-Profit-Assigning-Work/826. Most Profit Assigning Work_test.go
package leetcode import ( "fmt" "testing" ) type question826 struct { para826 ans826 } // para 是参数 // one 代表第一个参数 type para826 struct { one []int two []int three []int } // ans 是答案 // one 代表第一个答案 type ans826 struct { one int } func Test_Problem826(t *testing.T) { qs := []question826{ { para826{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0826.Most-Profit-Assigning-Work/826. Most Profit Assigning Work.go
leetcode/0826.Most-Profit-Assigning-Work/826. Most Profit Assigning Work.go
package leetcode import ( "fmt" "sort" ) // Task define type Task struct { Difficulty int Profit int } // Tasks define type Tasks []Task // Len define func (p Tasks) Len() int { return len(p) } // Swap define func (p Tasks) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // SortByDiff define type SortByDiff st...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0987.Vertical-Order-Traversal-of-a-Binary-Tree/987. Vertical Order Traversal of a Binary Tree.go
leetcode/0987.Vertical-Order-Traversal-of-a-Binary-Tree/987. Vertical Order Traversal of a Binary Tree.go
package leetcode import ( "math" "sort" "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ type node struct { x, y, val int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0987.Vertical-Order-Traversal-of-a-Binary-Tree/987. Vertical Order Traversal of a Binary Tree_test.go
leetcode/0987.Vertical-Order-Traversal-of-a-Binary-Tree/987. Vertical Order Traversal of a Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question987 struct { para987 ans987 } // para 是参数 // one 代表第一个参数 type para987 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans987 struct { one [][]int } func Test_Problem987(t *testing.T) { qs := []questi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0561.Array-Partition/561. Array Partition_test.go
leetcode/0561.Array-Partition/561. Array Partition_test.go
package leetcode import ( "fmt" "testing" ) type question561 struct { para561 ans561 } // para 是参数 // one 代表第一个参数 type para561 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans561 struct { one int } func Test_Problem561(t *testing.T) { qs := []question561{ { para561{[]int{}}, ans561{0}, }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0561.Array-Partition/561. Array Partition.go
leetcode/0561.Array-Partition/561. Array Partition.go
package leetcode func arrayPairSum(nums []int) int { array := [20001]int{} for i := 0; i < len(nums); i++ { array[nums[i]+10000]++ } flag, sum := true, 0 for i := 0; i < len(array); i++ { for array[i] > 0 { if flag { sum = sum + i - 10000 } flag = !flag array[i]-- } } return sum }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0103.Binary-Tree-Zigzag-Level-Order-Traversal/103. Binary Tree Zigzag Level Order Traversal_test.go
leetcode/0103.Binary-Tree-Zigzag-Level-Order-Traversal/103. Binary Tree Zigzag Level Order Traversal_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question103 struct { para103 ans103 } // para 是参数 // one 代表第一个参数 type para103 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans103 struct { one [][]int } func Test_Problem103(t *testing.T) { qs := []questi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0103.Binary-Tree-Zigzag-Level-Order-Traversal/103. Binary Tree Zigzag Level Order Traversal.go
leetcode/0103.Binary-Tree-Zigzag-Level-Order-Traversal/103. Binary Tree Zigzag Level Order Traversal.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ // 解法一 func zigzagLevelOrder(root *TreeNode) [][]i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0061.Rotate-List/61. Rotate List_test.go
leetcode/0061.Rotate-List/61. Rotate List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question61 struct { para61 ans61 } // para 是参数 // one 代表第一个参数 type para61 struct { one []int k int } // ans 是答案 // one 代表第一个答案 type ans61 struct { one []int } func Test_Problem61(t *testing.T) { qs := []quest...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0061.Rotate-List/61. Rotate List.go
leetcode/0061.Rotate-List/61. Rotate 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 rotateRight(head *ListNode, k int) *ListNode { if head == nil || hea...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0065.Valid-Number/65. Valid Number.go
leetcode/0065.Valid-Number/65. Valid Number.go
package leetcode func isNumber(s string) bool { numFlag, dotFlag, eFlag := false, false, false for i := 0; i < len(s); i++ { if '0' <= s[i] && s[i] <= '9' { numFlag = true } else if s[i] == '.' && !dotFlag && !eFlag { dotFlag = true } else if (s[i] == 'e' || s[i] == 'E') && !eFlag && numFlag { eFlag =...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0065.Valid-Number/65. Valid Number_test.go
leetcode/0065.Valid-Number/65. Valid Number_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem65(t *testing.T) { tcs := []struct { s string ans bool }{ { "0", true, }, { "e", false, }, { ".", false, }, { ".1", true, }, } fmt.Printf("------------------------Leetcode Problem 65------------------...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0918.Maximum-Sum-Circular-Subarray/918. Maximum Sum Circular Subarray.go
leetcode/0918.Maximum-Sum-Circular-Subarray/918. Maximum Sum Circular Subarray.go
package leetcode import "math" func maxSubarraySumCircular(nums []int) int { var max1, max2, sum int // case: no circulation max1 = int(math.Inf(-1)) l := len(nums) for i := 0; i < l; i++ { sum += nums[i] if sum > max1 { max1 = sum } if sum < 1 { sum = 0 } } // case: circling arr_sum := 0 f...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0918.Maximum-Sum-Circular-Subarray/918. Maximum Sum Circular Subarray_test.go
leetcode/0918.Maximum-Sum-Circular-Subarray/918. Maximum Sum Circular Subarray_test.go
package leetcode import ( "fmt" "testing" ) type question918 struct { para918 ans918 } // para 是参数 // one 代表第一个参数 type para918 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans918 struct { one int } func Test_Problem918(t *testing.T) { qs := []question918{ { para918{[]int{1, -2, 3, -2}}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0419.Battleships-in-a-Board/419. Battleships in a Board.go
leetcode/0419.Battleships-in-a-Board/419. Battleships in a Board.go
package leetcode func countBattleships(board [][]byte) (ans int) { if len(board) == 0 || len(board[0]) == 0 { return 0 } for i := range board { for j := range board[i] { if board[i][j] == 'X' { if i > 0 && board[i-1][j] == 'X' { continue } if j > 0 && board[i][j-1] == 'X' { continue ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0419.Battleships-in-a-Board/419. Battleships in a Board_test.go
leetcode/0419.Battleships-in-a-Board/419. Battleships in a Board_test.go
package leetcode import ( "fmt" "testing" "unsafe" ) type question419 struct { para419 ans419 } // para 是参数 // one 代表第一个参数 type para419 struct { one [][]byte } // ans 是答案 // one 代表第一个答案 type ans419 struct { one int } func Test_Problem419(t *testing.T) { qs := []question419{ { para419{[][]byte{{'X', ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0959.Regions-Cut-By-Slashes/959. Regions Cut By Slashes_test.go
leetcode/0959.Regions-Cut-By-Slashes/959. Regions Cut By Slashes_test.go
package leetcode import ( "fmt" "testing" ) type question959 struct { para959 ans959 } // para 是参数 // one 代表第一个参数 type para959 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans959 struct { one int } func Test_Problem959(t *testing.T) { qs := []question959{ { para959{[]string{" /", "/ "}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0959.Regions-Cut-By-Slashes/959. Regions Cut By Slashes.go
leetcode/0959.Regions-Cut-By-Slashes/959. Regions Cut By Slashes.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) func regionsBySlashes(grid []string) int { size := len(grid) uf := template.UnionFind{} uf.Init(4 * size * size) for i := 0; i < size; i++ { for j := 0; j < size; j++ { switch grid[i][j] { case '\\': uf.Union(getFaceIdx(size, i, j...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0838.Push-Dominoes/838. Push Dominoes_test.go
leetcode/0838.Push-Dominoes/838. Push Dominoes_test.go
package leetcode import ( "fmt" "testing" ) type question838 struct { para838 ans838 } // para 是参数 // one 代表第一个参数 type para838 struct { one string } // ans 是答案 // one 代表第一个答案 type ans838 struct { one string } func Test_Problem838(t *testing.T) { qs := []question838{ { para838{".L.R...LR..L.."}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0838.Push-Dominoes/838. Push Dominoes.go
leetcode/0838.Push-Dominoes/838. Push Dominoes.go
package leetcode // 解法一 func pushDominoes(dominoes string) string { d := []byte(dominoes) for i := 0; i < len(d); { j := i + 1 for j < len(d)-1 && d[j] == '.' { j++ } push(d[i : j+1]) i = j } return string(d) } func push(d []byte) { first, last := 0, len(d)-1 switch d[first] { case '.', 'L': if ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0887.Super-Egg-Drop/887. Super Egg Drop_test.go
leetcode/0887.Super-Egg-Drop/887. Super Egg Drop_test.go
package leetcode import ( "fmt" "testing" ) type question887 struct { para887 ans887 } // para 是参数 // one 代表第一个参数 type para887 struct { k int n int } // ans 是答案 // one 代表第一个答案 type ans887 struct { one int } func Test_Problem887(t *testing.T) { qs := []question887{ { para887{1, 2}, ans887{2}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0887.Super-Egg-Drop/887. Super Egg Drop.go
leetcode/0887.Super-Egg-Drop/887. Super Egg Drop.go
package leetcode // 解法一 二分搜索 func superEggDrop(K int, N int) int { low, high := 1, N for low < high { mid := low + (high-low)>>1 if counterF(K, N, mid) >= N { high = mid } else { low = mid + 1 } } return low } // 计算二项式和,特殊的第一项 C(t,0) = 1 func counterF(k, n, mid int) int { res, sum := 1, 0 for i :=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0636.Exclusive-Time-of-Functions/636. Exclusive Time of Functions_test.go
leetcode/0636.Exclusive-Time-of-Functions/636. Exclusive Time of Functions_test.go
package leetcode import ( "fmt" "testing" ) type question636 struct { para636 ans636 } // para 是参数 // one 代表第一个参数 type para636 struct { n int one []string } // ans 是答案 // one 代表第一个答案 type ans636 struct { one []int } func Test_Problem636(t *testing.T) { qs := []question636{ { para636{2, []string{"0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0636.Exclusive-Time-of-Functions/636. Exclusive Time of Functions.go
leetcode/0636.Exclusive-Time-of-Functions/636. Exclusive Time of Functions.go
package leetcode import ( "strconv" "strings" ) type log struct { id int order string time int } func exclusiveTime(n int, logs []string) []int { res, lastLog, stack := make([]int, n), log{id: -1, order: "", time: 0}, []log{} for i := 0; i < len(logs); i++ { a := strings.Split(logs[i], ":") id, _ := s...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0413.Arithmetic-Slices/413. Arithmetic Slices.go
leetcode/0413.Arithmetic-Slices/413. Arithmetic Slices.go
package leetcode func numberOfArithmeticSlices(A []int) int { if len(A) < 3 { return 0 } res, dp := 0, 0 for i := 1; i < len(A)-1; i++ { if A[i+1]-A[i] == A[i]-A[i-1] { dp++ res += dp } else { dp = 0 } } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0413.Arithmetic-Slices/413. Arithmetic Slices_test.go
leetcode/0413.Arithmetic-Slices/413. Arithmetic Slices_test.go
package leetcode import ( "fmt" "testing" ) type question413 struct { para413 ans413 } // para 是参数 // one 代表第一个参数 type para413 struct { A []int } // ans 是答案 // one 代表第一个答案 type ans413 struct { one int } func Test_Problem413(t *testing.T) { qs := []question413{ { para413{[]int{1, 2, 3, 4}}, ans413{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0445.Add-Two-Numbers-II/445. Add Two Numbers II_test.go
leetcode/0445.Add-Two-Numbers-II/445. Add Two Numbers II_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question445 struct { para445 ans445 } // para 是参数 // one 代表第一个参数 type para445 struct { one []int another []int } // ans 是答案 // one 代表第一个答案 type ans445 struct { one []int } func Test_Problem445(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/0445.Add-Two-Numbers-II/445. Add Two Numbers II.go
leetcode/0445.Add-Two-Numbers-II/445. Add Two Numbers 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 addTwoNumbers445(l1 *ListNode, l2 *ListNode) *ListNode { if l1 == ni...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0966.Vowel-Spellchecker/966. Vowel Spellchecker.go
leetcode/0966.Vowel-Spellchecker/966. Vowel Spellchecker.go
package leetcode import "strings" func spellchecker(wordlist []string, queries []string) []string { wordsPerfect, wordsCap, wordsVowel := map[string]bool{}, map[string]string{}, map[string]string{} for _, word := range wordlist { wordsPerfect[word] = true wordLow := strings.ToLower(word) if _, ok := wordsCap[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0966.Vowel-Spellchecker/966. Vowel Spellchecker_test.go
leetcode/0966.Vowel-Spellchecker/966. Vowel Spellchecker_test.go
package leetcode import ( "fmt" "testing" ) type question966 struct { para966 ans966 } // para 是参数 // one 代表第一个参数 type para966 struct { wordlist []string queries []string } // ans 是答案 // one 代表第一个答案 type ans966 struct { one []string } func Test_Problem966(t *testing.T) { qs := []question966{ { para9...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1518.Water-Bottles/1518.Water Bottles.go
leetcode/1518.Water-Bottles/1518.Water Bottles.go
package leetcode func numWaterBottles(numBottles int, numExchange int) int { if numBottles < numExchange { return numBottles } quotient := numBottles / numExchange reminder := numBottles % numExchange ans := numBottles + quotient for quotient+reminder >= numExchange { quotient, reminder = (quotient+reminder)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1518.Water-Bottles/1518.Water Bottles_test.go
leetcode/1518.Water-Bottles/1518.Water Bottles_test.go
package leetcode import ( "fmt" "testing" ) type question1518 struct { para1518 ans1518 } // para 是参数 type para1518 struct { numBottles int numExchange int } // ans 是答案 type ans1518 struct { ans int } func Test_Problem1518(t *testing.T) { qs := []question1518{ { para1518{9, 3}, ans1518{13}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0102.Binary-Tree-Level-Order-Traversal/102. Binary Tree Level Order Traversal.go
leetcode/0102.Binary-Tree-Level-Order-Traversal/102. Binary Tree Level Order Traversal.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ // 解法一 BFS func levelOrder(root *TreeNode) [][]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0102.Binary-Tree-Level-Order-Traversal/102. Binary Tree Level Order Traversal_test.go
leetcode/0102.Binary-Tree-Level-Order-Traversal/102. Binary Tree Level Order Traversal_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question102 struct { para102 ans102 } // para 是参数 // one 代表第一个参数 type para102 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans102 struct { one [][]int } func Test_Problem102(t *testing.T) { qs := []questi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1642.Furthest-Building-You-Can-Reach/1642. Furthest Building You Can Reach_test.go
leetcode/1642.Furthest-Building-You-Can-Reach/1642. Furthest Building You Can Reach_test.go
package leetcode import ( "fmt" "testing" ) type question1642 struct { para1642 ans1642 } // para 是参数 // one 代表第一个参数 type para1642 struct { heights []int bricks int ladders int } // ans 是答案 // one 代表第一个答案 type ans1642 struct { one int } func Test_Problem1642(t *testing.T) { qs := []question1642{ { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1642.Furthest-Building-You-Can-Reach/1642. Furthest Building You Can Reach.go
leetcode/1642.Furthest-Building-You-Can-Reach/1642. Furthest Building You Can Reach.go
package leetcode import ( "container/heap" ) func furthestBuilding(heights []int, bricks int, ladder int) int { usedLadder := &heightDiffPQ{} for i := 1; i < len(heights); i++ { needbricks := heights[i] - heights[i-1] if needbricks < 0 { continue } if ladder > 0 { heap.Push(usedLadder, needbricks) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0668.Kth-Smallest-Number-in-Multiplication-Table/668. Kth Smallest Number in Multiplication Table.go
leetcode/0668.Kth-Smallest-Number-in-Multiplication-Table/668. Kth Smallest Number in Multiplication Table.go
package leetcode import "math" func findKthNumber(m int, n int, k int) int { low, high := 1, m*n for low < high { mid := low + (high-low)>>1 if counterKthNum(m, n, mid) >= k { high = mid } else { low = mid + 1 } } return low } func counterKthNum(m, n, mid int) int { count := 0 for i := 1; i <= m;...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0668.Kth-Smallest-Number-in-Multiplication-Table/668. Kth Smallest Number in Multiplication Table_test.go
leetcode/0668.Kth-Smallest-Number-in-Multiplication-Table/668. Kth Smallest Number in Multiplication Table_test.go
package leetcode import ( "fmt" "testing" ) type question668 struct { para668 ans668 } // para 是参数 // one 代表第一个参数 type para668 struct { m int n int k int } // ans 是答案 // one 代表第一个答案 type ans668 struct { one int } func Test_Problem668(t *testing.T) { qs := []question668{ { para668{3, 3, 5}, ans66...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0027.Remove-Element/27. Remove Element.go
leetcode/0027.Remove-Element/27. Remove Element.go
package leetcode func removeElement(nums []int, val int) int { if len(nums) == 0 { return 0 } j := 0 for i := 0; i < len(nums); i++ { if nums[i] != val { if i != j { nums[i], nums[j] = nums[j], nums[i] } j++ } } return j }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0027.Remove-Element/27. Remove Element_test.go
leetcode/0027.Remove-Element/27. Remove Element_test.go
package leetcode import ( "fmt" "testing" ) type question27 struct { para27 ans27 } // para 是参数 // one 代表第一个参数 type para27 struct { one []int two int } // ans 是答案 // one 代表第一个答案 type ans27 struct { one int } func Test_Problem27(t *testing.T) { qs := []question27{ { para27{[]int{1, 0, 1}, 1}, ans2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique.go
leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique.go
package leetcode import ( "sort" ) func minDeletions(s string) int { frequency, res := make([]int, 26), 0 for i := 0; i < len(s); i++ { frequency[s[i]-'a']++ } sort.Sort(sort.Reverse(sort.IntSlice(frequency))) for i := 1; i <= 25; i++ { if frequency[i] == frequency[i-1] && frequency[i] != 0 { res++ fr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique_test.go
leetcode/1647.Minimum-Deletions-to-Make-Character-Frequencies-Unique/1647. Minimum Deletions to Make Character Frequencies Unique_test.go
package leetcode import ( "fmt" "testing" ) type question1647 struct { para1647 ans1647 } // para 是参数 // one 代表第一个参数 type para1647 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1647 struct { one int } func Test_Problem1647(t *testing.T) { qs := []question1647{ { para1647{"aab"}, ans1647{0}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1189.Maximum-Number-of-Balloons/1189. Maximum Number of Balloons.go
leetcode/1189.Maximum-Number-of-Balloons/1189. Maximum Number of Balloons.go
package leetcode func maxNumberOfBalloons(text string) int { fre := make([]int, 26) for _, t := range text { fre[t-'a']++ } // 字符 b 的频次是数组下标 1 对应的元素值 // 字符 a 的频次是数组下标 0 对应的元素值 // 字符 l 的频次是数组下标 11 对应的元素值,这里有 2 个 l,所以元素值需要除以 2 // 字符 o 的频次是数组下标 14 对应的元素值,这里有 2 个 o,所以元素值需要除以 2 // 字符 n 的频次是数组下标 13 对应的元素值 return ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1189.Maximum-Number-of-Balloons/1189. Maximum Number of Balloons_test.go
leetcode/1189.Maximum-Number-of-Balloons/1189. Maximum Number of Balloons_test.go
package leetcode import ( "fmt" "testing" ) type question1189 struct { para1189 ans1189 } // para 是参数 // one 代表第一个参数 type para1189 struct { text string } // ans 是答案 // one 代表第一个答案 type ans1189 struct { one int } func Test_Problem1189(t *testing.T) { qs := []question1189{ { para1189{"nlaebolko"}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0189.Rotate-Array/189. Rotate Array_test.go
leetcode/0189.Rotate-Array/189. Rotate Array_test.go
package leetcode import ( "fmt" "testing" ) type question189 struct { para189 ans189 } // para 是参数 // one 代表第一个参数 type para189 struct { nums []int k int } // ans 是答案 // one 代表第一个答案 type ans189 struct { one []int } func Test_Problem189(t *testing.T) { qs := []question189{ { para189{[]int{1, 2, 3, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0189.Rotate-Array/189. Rotate Array.go
leetcode/0189.Rotate-Array/189. Rotate Array.go
package leetcode // 解法一 时间复杂度 O(n),空间复杂度 O(1) func rotate(nums []int, k int) { k %= len(nums) reverse(nums) reverse(nums[:k]) reverse(nums[k:]) } func reverse(a []int) { for i, n := 0, len(a); i < n/2; i++ { a[i], a[n-1-i] = a[n-1-i], a[i] } } // 解法二 时间复杂度 O(n),空间复杂度 O(n) func rotate1(nums []int, k int) { n...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1332.Remove-Palindromic-Subsequences/1332. Remove Palindromic Subsequences.go
leetcode/1332.Remove-Palindromic-Subsequences/1332. Remove Palindromic Subsequences.go
package leetcode func removePalindromeSub(s string) int { if len(s) == 0 { return 0 } for i := 0; i < len(s)/2; i++ { if s[i] != s[len(s)-1-i] { return 2 } } return 1 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1332.Remove-Palindromic-Subsequences/1332. Remove Palindromic Subsequences_test.go
leetcode/1332.Remove-Palindromic-Subsequences/1332. Remove Palindromic Subsequences_test.go
package leetcode import ( "fmt" "testing" ) type question1332 struct { para1332 ans1332 } // para 是参数 // one 代表第一个参数 type para1332 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1332 struct { one int } func Test_Problem1332(t *testing.T) { qs := []question1332{ { para1332{"ababa"}, ans1332{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0063.Unique-Paths-II/63. Unique Paths II_test.go
leetcode/0063.Unique-Paths-II/63. Unique Paths II_test.go
package leetcode import ( "fmt" "testing" ) type question63 struct { para63 ans63 } // para 是参数 // one 代表第一个参数 type para63 struct { og [][]int } // ans 是答案 // one 代表第一个答案 type ans63 struct { one int } func Test_Problem63(t *testing.T) { qs := []question63{ { para63{[][]int{ {0, 0, 0}, {0, 1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0063.Unique-Paths-II/63. Unique Paths II.go
leetcode/0063.Unique-Paths-II/63. Unique Paths II.go
package leetcode func uniquePathsWithObstacles(obstacleGrid [][]int) int { if len(obstacleGrid) == 0 || obstacleGrid[0][0] == 1 { return 0 } m, n := len(obstacleGrid), len(obstacleGrid[0]) dp := make([][]int, m) for i := 0; i < m; i++ { dp[i] = make([]int, n) } dp[0][0] = 1 for i := 1; i < n; i++ { if dp...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0190.Reverse-Bits/190. Reverse Bits.go
leetcode/0190.Reverse-Bits/190. Reverse Bits.go
package leetcode func reverseBits(num uint32) uint32 { var res uint32 for i := 0; i < 32; i++ { res = res<<1 | num&1 num >>= 1 } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0190.Reverse-Bits/190. Reverse Bits_test.go
leetcode/0190.Reverse-Bits/190. Reverse Bits_test.go
package leetcode import ( "fmt" "strconv" "testing" ) type question190 struct { para190 ans190 } // para 是参数 // one 代表第一个参数 type para190 struct { one uint32 } // ans 是答案 // one 代表第一个答案 type ans190 struct { one uint32 } func Test_Problem190(t *testing.T) { qs := []question190{ { para190{43261596}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0996.Number-of-Squareful-Arrays/996. Number of Squareful Arrays.go
leetcode/0996.Number-of-Squareful-Arrays/996. Number of Squareful Arrays.go
package leetcode import ( "math" "sort" ) func numSquarefulPerms(A []int) int { if len(A) == 0 { return 0 } used, p, res := make([]bool, len(A)), []int{}, [][]int{} sort.Ints(A) // 这里是去重的关键逻辑 generatePermutation996(A, 0, p, &res, &used) return len(res) } func generatePermutation996(nums []int, index int, p...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0996.Number-of-Squareful-Arrays/996. Number of Squareful Arrays_test.go
leetcode/0996.Number-of-Squareful-Arrays/996. Number of Squareful Arrays_test.go
package leetcode import ( "fmt" "testing" ) type question996 struct { para996 ans996 } // para 是参数 // one 代表第一个参数 type para996 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans996 struct { one int } func Test_Problem996(t *testing.T) { qs := []question996{ { para996{[]int{1, 17, 8}}, ans996{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0491.Non-decreasing-Subsequences/491. Non-decreasing Subsequences_test.go
leetcode/0491.Non-decreasing-Subsequences/491. Non-decreasing Subsequences_test.go
package leetcode import ( "fmt" "testing" ) type question491 struct { para491 ans491 } // para 是参数 // one 代表第一个参数 type para491 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans491 struct { one [][]int } func Test_Problem491(t *testing.T) { qs := []question491{ { para491{[]int{4, 3, 2, 1}}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0491.Non-decreasing-Subsequences/491. Non-decreasing Subsequences.go
leetcode/0491.Non-decreasing-Subsequences/491. Non-decreasing Subsequences.go
package leetcode func findSubsequences(nums []int) [][]int { c, visited, res := []int{}, map[int]bool{}, [][]int{} for i := 0; i < len(nums)-1; i++ { if _, ok := visited[nums[i]]; ok { continue } else { visited[nums[i]] = true generateIncSubsets(nums, i, c, &res) } } return res } func generateIncSu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0049.Group-Anagrams/49. Group Anagrams.go
leetcode/0049.Group-Anagrams/49. Group Anagrams.go
package leetcode import "sort" type sortRunes []rune func (s sortRunes) Less(i, j int) bool { return s[i] < s[j] } func (s sortRunes) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s sortRunes) Len() int { return len(s) } func groupAnagrams(strs []string) [][]string { record, res := map[string][]string{}, [...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0049.Group-Anagrams/49. Group Anagrams_test.go
leetcode/0049.Group-Anagrams/49. Group Anagrams_test.go
package leetcode import ( "fmt" "testing" ) type question49 struct { para49 ans49 } // para 是参数 // one 代表第一个参数 type para49 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans49 struct { one [][]string } func Test_Problem49(t *testing.T) { qs := []question49{ { para49{[]string{"eat", "tea", "ta...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character/1170. Compare Strings by Frequency of the Smallest Character.go
leetcode/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character/1170. Compare Strings by Frequency of the Smallest Character.go
package leetcode import "sort" func numSmallerByFrequency(queries []string, words []string) []int { ws, res := make([]int, len(words)), make([]int, len(queries)) for i, w := range words { ws[i] = countFunc(w) } sort.Ints(ws) for i, q := range queries { fq := countFunc(q) res[i] = len(words) - sort.Search(l...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character/1170. Compare Strings by Frequency of the Smallest Character_test.go
leetcode/1170.Compare-Strings-by-Frequency-of-the-Smallest-Character/1170. Compare Strings by Frequency of the Smallest Character_test.go
package leetcode import ( "fmt" "testing" ) type question1170 struct { para1170 ans1170 } // para 是参数 // one 代表第一个参数 type para1170 struct { queries []string words []string } // ans 是答案 // one 代表第一个答案 type ans1170 struct { one []int } func Test_Problem1170(t *testing.T) { qs := []question1170{ { pa...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0706.Design-HashMap/706. Design HashMap.go
leetcode/0706.Design-HashMap/706. Design HashMap.go
package leetcode const Len int = 10000 type MyHashMap struct { content [Len]*HashNode } type HashNode struct { key int val int next *HashNode } func (N *HashNode) Put(key int, value int) { if N.key == key { N.val = value return } if N.next == nil { N.next = &HashNode{key, value, nil} return } N.n...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0706.Design-HashMap/706. Design HashMap_test.go
leetcode/0706.Design-HashMap/706. Design HashMap_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem706(t *testing.T) { obj := Constructor706() obj.Put(7, 10) fmt.Printf("Get 7 = %v\n", obj.Get(7)) obj.Put(7, 20) fmt.Printf("Contains 7 = %v\n", obj.Get(7)) param1 := obj.Get(100) fmt.Printf("param1 = %v\n", param1) obj.Remove(100007) param1 = ob...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0692.Top-K-Frequent-Words/692. Top K Frequent Words.go
leetcode/0692.Top-K-Frequent-Words/692. Top K Frequent Words.go
package leetcode import "container/heap" func topKFrequent(words []string, k int) []string { m := map[string]int{} for _, word := range words { m[word]++ } pq := &PQ{} heap.Init(pq) for w, c := range m { heap.Push(pq, &wordCount{w, c}) if pq.Len() > k { heap.Pop(pq) } } res := make([]string, k) fo...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0692.Top-K-Frequent-Words/692. Top K Frequent Words_test.go
leetcode/0692.Top-K-Frequent-Words/692. Top K Frequent Words_test.go
package leetcode import ( "fmt" "testing" ) type question692 struct { para692 ans692 } // para 是参数 // one 代表第一个参数 type para692 struct { words []string k int } // ans 是答案 // one 代表第一个答案 type ans692 struct { one []string } func Test_Problem692(t *testing.T) { qs := []question692{ { para692{[]strin...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0535.Encode-and-Decode-TinyURL/535. Encode and Decode TinyURL_test.go
leetcode/0535.Encode-and-Decode-TinyURL/535. Encode and Decode TinyURL_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem535(t *testing.T) { obj := Constructor() fmt.Printf("obj = %v\n", obj) e := obj.encode("https://leetcode.com/problems/design-tinyurl") fmt.Printf("obj encode = %v\n", e) d := obj.decode(e) fmt.Printf("obj decode = %v\n", d) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0535.Encode-and-Decode-TinyURL/535. Encode and Decode TinyURL.go
leetcode/0535.Encode-and-Decode-TinyURL/535. Encode and Decode TinyURL.go
package leetcode import ( "fmt" "strconv" "strings" ) type Codec struct { urls []string } func Constructor() Codec { return Codec{[]string{}} } // Encodes a URL to a shortened URL. func (this *Codec) encode(longUrl string) string { this.urls = append(this.urls, longUrl) return "http://tinyurl.com/" + fmt.Spr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0473.Matchsticks-to-Square/473. Matchsticks to Square.go
leetcode/0473.Matchsticks-to-Square/473. Matchsticks to Square.go
package leetcode import "sort" func makesquare(matchsticks []int) bool { if len(matchsticks) < 4 { return false } total := 0 for _, v := range matchsticks { total += v } if total%4 != 0 { return false } sort.Slice(matchsticks, func(i, j int) bool { return matchsticks[i] > matchsticks[j] }) visited :...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0473.Matchsticks-to-Square/473. Matchsticks to Square_test.go
leetcode/0473.Matchsticks-to-Square/473. Matchsticks to Square_test.go
package leetcode import ( "fmt" "testing" ) type question473 struct { para473 ans473 } // para 是参数 // one 代表第一个参数 type para473 struct { arr []int } // ans 是答案 // one 代表第一个答案 type ans473 struct { one bool } func Test_Problem473(t *testing.T) { qs := []question473{ { para473{[]int{1, 1, 2, 2, 2}}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence/1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence_test.go
leetcode/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence/1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence_test.go
package leetcode import ( "fmt" "testing" ) type question1455 struct { para1455 ans1455 } // para 是参数 // one 代表第一个参数 type para1455 struct { sentence string searchWord string } // ans 是答案 // one 代表第一个答案 type ans1455 struct { one int } func Test_Problem1455(t *testing.T) { qs := []question1455{ { pa...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence/1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence.go
leetcode/1455.Check-If-a-Word-Occurs-As-a-Prefix-of-Any-Word-in-a-Sentence/1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence.go
package leetcode import "strings" func isPrefixOfWord(sentence string, searchWord string) int { for i, v := range strings.Split(sentence, " ") { if strings.HasPrefix(v, searchWord) { return i + 1 } } return -1 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0523.Continuous-Subarray-Sum/523. Continuous Subarray Sum_test.go
leetcode/0523.Continuous-Subarray-Sum/523. Continuous Subarray Sum_test.go
package leetcode import ( "fmt" "testing" ) type question523 struct { para523 ans523 } // para 是参数 // one 代表第一个参数 type para523 struct { nums []int k int } // ans 是答案 // one 代表第一个答案 type ans523 struct { one bool } func Test_Problem523(t *testing.T) { qs := []question523{ { para523{[]int{23, 2, 4, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0523.Continuous-Subarray-Sum/523. Continuous Subarray Sum.go
leetcode/0523.Continuous-Subarray-Sum/523. Continuous Subarray Sum.go
package leetcode func checkSubarraySum(nums []int, k int) bool { m := make(map[int]int) m[0] = -1 sum := 0 for i, n := range nums { sum += n if r, ok := m[sum%k]; ok { if i-2 >= r { return true } } else { m[sum%k] = i } } return false }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0412.Fizz-Buzz/412. Fizz Buzz.go
leetcode/0412.Fizz-Buzz/412. Fizz Buzz.go
package leetcode import "strconv" func fizzBuzz(n int) []string { solution := make([]string, n) for i := 1; i <= n; i++ { solution[i-1] = "" if i%3 == 0 { solution[i-1] += "Fizz" } if i%5 == 0 { solution[i-1] += "Buzz" } if solution[i-1] == "" { solution[i-1] = strconv.Itoa(i) } } return so...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0412.Fizz-Buzz/412. Fizz Buzz_test.go
leetcode/0412.Fizz-Buzz/412. Fizz Buzz_test.go
package leetcode import ( "fmt" "testing" ) var tcs = []struct { n int ans []string }{ { 15, []string{ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", }, }, } func Test_fizzBuzz(t *testing.T) { fmt.Pri...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990975.Odd-Even-Jump/975. Odd Even Jump.go
leetcode/9990975.Odd-Even-Jump/975. Odd Even Jump.go
package leetcode import ( "fmt" ) func oddEvenJumps(A []int) int { oddJumpMap, evenJumpMap, current, res := map[int]int{}, map[int]int{}, 0, 0 for i := 0; i < len(A); i++ { for j := i + 1; j < len(A); j++ { if v, ok := oddJumpMap[i]; ok { if A[i] <= A[j] && A[j] <= A[v] { if A[j] == A[v] && j < oddJu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990975.Odd-Even-Jump/975. Odd Even Jump_test.go
leetcode/9990975.Odd-Even-Jump/975. Odd Even Jump_test.go
package leetcode import ( "fmt" "testing" ) type question975 struct { para975 ans975 } // para 是参数 // one 代表第一个参数 type para975 struct { A []int } // ans 是答案 // one 代表第一个答案 type ans975 struct { one int } func Test_Problem975(t *testing.T) { qs := []question975{ { para975{[]int{10, 13, 12, 14, 15}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0942.DI-String-Match/942. DI String Match_test.go
leetcode/0942.DI-String-Match/942. DI String Match_test.go
package leetcode import ( "fmt" "testing" ) type question942 struct { para942 ans942 } // para 是参数 // one 代表第一个参数 type para942 struct { S string } // ans 是答案 // one 代表第一个答案 type ans942 struct { one []int } func Test_Problem942(t *testing.T) { qs := []question942{ { para942{"IDID"}, ans942{[]int{0,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0942.DI-String-Match/942. DI String Match.go
leetcode/0942.DI-String-Match/942. DI String Match.go
package leetcode func diStringMatch(S string) []int { result, maxNum, minNum, index := make([]int, len(S)+1), len(S), 0, 0 for _, ch := range S { if ch == 'I' { result[index] = minNum minNum++ } else { result[index] = maxNum maxNum-- } index++ } result[index] = minNum return result }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0907.Sum-of-Subarray-Minimums/907. Sum of Subarray Minimums_test.go
leetcode/0907.Sum-of-Subarray-Minimums/907. Sum of Subarray Minimums_test.go
package leetcode import ( "fmt" "testing" ) type question907 struct { para907 ans907 } // para 是参数 // one 代表第一个参数 type para907 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans907 struct { one int } func Test_Problem907(t *testing.T) { qs := []question907{ { para907{[]int{3, 1, 2, 4}}, ans90...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0907.Sum-of-Subarray-Minimums/907. Sum of Subarray Minimums.go
leetcode/0907.Sum-of-Subarray-Minimums/907. Sum of Subarray Minimums.go
package leetcode // 解法一 最快的解是 DP + 单调栈 func sumSubarrayMins(A []int) int { stack, dp, res, mod := []int{}, make([]int, len(A)+1), 0, 1000000007 stack = append(stack, -1) for i := 0; i < len(A); i++ { for stack[len(stack)-1] != -1 && A[i] <= A[stack[len(stack)-1]] { stack = stack[:len(stack)-1] } dp[i+1] =...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0503.Next-Greater-Element-II/503. Next Greater Element II.go
leetcode/0503.Next-Greater-Element-II/503. Next Greater Element II.go
package leetcode // 解法一 单调栈 func nextGreaterElements(nums []int) []int { res := make([]int, 0) indexes := make([]int, 0) for i := 0; i < len(nums); i++ { res = append(res, -1) } for i := 0; i < len(nums)*2; i++ { num := nums[i%len(nums)] for len(indexes) > 0 && nums[indexes[len(indexes)-1]] < num { index...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0503.Next-Greater-Element-II/503. Next Greater Element II_test.go
leetcode/0503.Next-Greater-Element-II/503. Next Greater Element II_test.go
package leetcode import ( "fmt" "testing" ) type question503 struct { para503 ans503 } // para 是参数 // one 代表第一个参数 type para503 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans503 struct { one []int } func Test_Problem503(t *testing.T) { qs := []question503{ { para503{[]int{}}, ans503{[]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0018.4Sum/18. 4Sum.go
leetcode/0018.4Sum/18. 4Sum.go
package leetcode import "sort" // 解法一 双指针 func fourSum(nums []int, target int) (quadruplets [][]int) { sort.Ints(nums) n := len(nums) for i := 0; i < n-3 && nums[i]+nums[i+1]+nums[i+2]+nums[i+3] <= target; i++ { if i > 0 && nums[i] == nums[i-1] || nums[i]+nums[n-3]+nums[n-2]+nums[n-1] < target { continue } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0018.4Sum/18. 4Sum_test.go
leetcode/0018.4Sum/18. 4Sum_test.go
package leetcode import ( "fmt" "testing" ) type question18 struct { para18 ans18 } // para 是参数 // one 代表第一个参数 type para18 struct { a []int t int } // ans 是答案 // one 代表第一个答案 type ans18 struct { one [][]int } func Test_Problem18(t *testing.T) { qs := []question18{ { para18{[]int{1, 1, 1, 1}, 4}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0043.Multiply-Strings/43. Multiply Strings_test.go
leetcode/0043.Multiply-Strings/43. Multiply Strings_test.go
package leetcode import ( "fmt" "testing" ) type question43 struct { para43 ans43 } // para 是参数 // one 代表第一个参数 type para43 struct { num1 string num2 string } // ans 是答案 // one 代表第一个答案 type ans43 struct { one string } func Test_Problem43(t *testing.T) { qs := []question43{ { para43{"2", "3"}, ans4...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0043.Multiply-Strings/43. Multiply Strings.go
leetcode/0043.Multiply-Strings/43. Multiply Strings.go
package leetcode func multiply(num1 string, num2 string) string { if num1 == "0" || num2 == "0" { return "0" } b1, b2, tmp := []byte(num1), []byte(num2), make([]int, len(num1)+len(num2)) for i := 0; i < len(b1); i++ { for j := 0; j < len(b2); j++ { tmp[i+j+1] += int(b1[i]-'0') * int(b2[j]-'0') } } for i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0053.Maximum-Subarray/53. Maximum Subarray_test.go
leetcode/0053.Maximum-Subarray/53. Maximum Subarray_test.go
package leetcode import ( "fmt" "testing" ) type question53 struct { para53 ans53 } // para 是参数 // one 代表第一个参数 type para53 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans53 struct { one int } func Test_Problem53(t *testing.T) { qs := []question53{ { para53{[]int{-2, 1, -3, 4, -1, 2, 1, -5, 4}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0053.Maximum-Subarray/53. Maximum Subarray.go
leetcode/0053.Maximum-Subarray/53. Maximum Subarray.go
package leetcode // 解法一 DP func maxSubArray(nums []int) int { if len(nums) == 0 { return 0 } if len(nums) == 1 { return nums[0] } dp, res := make([]int, len(nums)), nums[0] dp[0] = nums[0] for i := 1; i < len(nums); i++ { if dp[i-1] > 0 { dp[i] = nums[i] + dp[i-1] } else { dp[i] = nums[i] } re...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false