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/1816.Truncate-Sentence/1816.Truncate Sentence_test.go
leetcode/1816.Truncate-Sentence/1816.Truncate Sentence_test.go
package leetcode import ( "fmt" "testing" ) type question1816 struct { para1816 ans1816 } // para 是参数 type para1816 struct { s string k int } // ans 是答案 type ans1816 struct { ans string } func Test_Problem1816(t *testing.T) { qs := []question1816{ { para1816{"Hello how are you Contestant", 4}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1816.Truncate-Sentence/1816.Truncate Sentence.go
leetcode/1816.Truncate-Sentence/1816.Truncate Sentence.go
package leetcode func truncateSentence(s string, k int) string { end := 0 for i := range s { if k > 0 && s[i] == ' ' { k-- } if k == 0 { end = i break } } if end == 0 { return s } return s[:end] }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1486.XOR-Operation-in-an-Array/1486. XOR Operation in an Array.go
leetcode/1486.XOR-Operation-in-an-Array/1486. XOR Operation in an Array.go
package leetcode func xorOperation(n int, start int) int { res := 0 for i := 0; i < n; i++ { res ^= start + 2*i } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1486.XOR-Operation-in-an-Array/1486. XOR Operation in an Array_test.go
leetcode/1486.XOR-Operation-in-an-Array/1486. XOR Operation in an Array_test.go
package leetcode import ( "fmt" "testing" ) type question1486 struct { para1486 ans1486 } // para 是参数 // one 代表第一个参数 type para1486 struct { n int start int } // ans 是答案 // one 代表第一个答案 type ans1486 struct { one int } func Test_Problem1486(t *testing.T) { qs := []question1486{ { para1486{5, 0}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0713.Subarray-Product-Less-Than-K/713. Subarray Product Less Than K.go
leetcode/0713.Subarray-Product-Less-Than-K/713. Subarray Product Less Than K.go
package leetcode func numSubarrayProductLessThanK(nums []int, k int) int { if len(nums) == 0 { return 0 } res, left, right, prod := 0, 0, 0, 1 for left < len(nums) { if right < len(nums) && prod*nums[right] < k { prod = prod * nums[right] right++ } else if left == right { left++ right++ } else ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0713.Subarray-Product-Less-Than-K/713. Subarray Product Less Than K_test.go
leetcode/0713.Subarray-Product-Less-Than-K/713. Subarray Product Less Than K_test.go
package leetcode import ( "fmt" "testing" ) type question713 struct { para713 ans713 } // para 是参数 // one 代表第一个参数 type para713 struct { s []int k int } // ans 是答案 // one 代表第一个答案 type ans713 struct { one int } func Test_Problem713(t *testing.T) { qs := []question713{ { para713{[]int{10, 5, 2, 6}, 100...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0367.Valid-Perfect-Square/367. Valid Perfect Square.go
leetcode/0367.Valid-Perfect-Square/367. Valid Perfect Square.go
package leetcode func isPerfectSquare(num int) bool { low, high := 1, num for low <= high { mid := low + (high-low)>>1 if mid*mid == num { return true } else if mid*mid < num { low = mid + 1 } else { high = mid - 1 } } return false }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0367.Valid-Perfect-Square/367. Valid Perfect Square_test.go
leetcode/0367.Valid-Perfect-Square/367. Valid Perfect Square_test.go
package leetcode import ( "fmt" "testing" ) type question367 struct { para367 ans367 } // para 是参数 // one 代表第一个参数 type para367 struct { one int } // ans 是答案 // one 代表第一个答案 type ans367 struct { one bool } func Test_Problem367(t *testing.T) { qs := []question367{ { para367{1}, ans367{true}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0933.Number-of-Recent-Calls/933. Number of Recent Calls_test.go
leetcode/0933.Number-of-Recent-Calls/933. Number of Recent Calls_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem933(t *testing.T) { obj := Constructor933() fmt.Printf("obj = %v\n", obj) param1 := obj.Ping(1) fmt.Printf("param = %v\n", param1) param1 = obj.Ping(100) fmt.Printf("param = %v\n", param1) param1 = obj.Ping(3001) fmt.Printf("param = %v\n", param1)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0933.Number-of-Recent-Calls/933. Number of Recent Calls.go
leetcode/0933.Number-of-Recent-Calls/933. Number of Recent Calls.go
package leetcode import "sort" type RecentCounter struct { list []int } func Constructor933() RecentCounter { return RecentCounter{ list: []int{}, } } func (this *RecentCounter) Ping(t int) int { this.list = append(this.list, t) index := sort.Search(len(this.list), func(i int) bool { return this.list[i] >= t...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0990.Satisfiability-of-Equality-Equations/990. Satisfiability of Equality Equations_test.go
leetcode/0990.Satisfiability-of-Equality-Equations/990. Satisfiability of Equality Equations_test.go
package leetcode import ( "fmt" "testing" ) type question990 struct { para990 ans990 } // para 是参数 // one 代表第一个参数 type para990 struct { a []string } // ans 是答案 // one 代表第一个答案 type ans990 struct { one bool } func Test_Problem990(t *testing.T) { qs := []question990{ { para990{[]string{"a==b", "b!=a"}},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0990.Satisfiability-of-Equality-Equations/990. Satisfiability of Equality Equations.go
leetcode/0990.Satisfiability-of-Equality-Equations/990. Satisfiability of Equality Equations.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) func equationsPossible(equations []string) bool { if len(equations) == 0 { return false } uf := template.UnionFind{} uf.Init(26) for _, equ := range equations { if equ[1] == '=' && equ[2] == '=' { uf.Union(int(equ[0]-'a'), int(equ[3]-...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0217.Contains-Duplicate/217. Contains Duplicate.go
leetcode/0217.Contains-Duplicate/217. Contains Duplicate.go
package leetcode func containsDuplicate(nums []int) bool { record := make(map[int]bool, len(nums)) for _, n := range nums { if _, found := record[n]; found { return true } record[n] = true } return false }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0217.Contains-Duplicate/217. Contains Duplicate_test.go
leetcode/0217.Contains-Duplicate/217. Contains Duplicate_test.go
package leetcode import ( "fmt" "testing" ) type question217 struct { para217 ans217 } // para 是参数 // one 代表第一个参数 type para217 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans217 struct { one bool } func Test_Problem217(t *testing.T) { qs := []question217{ { para217{[]int{1, 2, 3, 1}}, ans2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0807.Max-Increase-to-Keep-City-Skyline/807.Max Increase to Keep City Skyline_test.go
leetcode/0807.Max-Increase-to-Keep-City-Skyline/807.Max Increase to Keep City Skyline_test.go
package leetcode import ( "fmt" "testing" ) type question807 struct { para807 ans807 } // para 是参数 type para807 struct { grid [][]int } // ans 是答案 type ans807 struct { ans int } func Test_Problem807(t *testing.T) { qs := []question807{ { para807{[][]int{{3, 0, 8, 4}, {2, 4, 5, 7}, {9, 2, 6, 3}, {0, 3...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0807.Max-Increase-to-Keep-City-Skyline/807.Max Increase to Keep City Skyline.go
leetcode/0807.Max-Increase-to-Keep-City-Skyline/807.Max Increase to Keep City Skyline.go
package leetcode func maxIncreaseKeepingSkyline(grid [][]int) int { n := len(grid) topBottomSkyline := make([]int, 0, n) leftRightSkyline := make([]int, 0, n) for i := range grid { cur := 0 for _, v := range grid[i] { if cur < v { cur = v } } leftRightSkyline = append(leftRightSkyline, cur) } f...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0653.Two-Sum-IV-Input-is-a-BST/653. Two Sum IV - Input is a BST.go
leetcode/0653.Two-Sum-IV-Input-is-a-BST/653. Two Sum IV - Input is a BST.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func findTarget(root *TreeNode, k int) bool { m :...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0653.Two-Sum-IV-Input-is-a-BST/653. Two Sum IV - Input is a BST_test.go
leetcode/0653.Two-Sum-IV-Input-is-a-BST/653. Two Sum IV - Input is a BST_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question653 struct { para653 ans653 } // para 是参数 // one 代表第一个参数 type para653 struct { one []int k int } // ans 是答案 // one 代表第一个答案 type ans653 struct { one bool } func Test_Problem653(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/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value.go
leetcode/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value.go
package leetcode func maximumUniqueSubarray(nums []int) int { if len(nums) == 0 { return 0 } result, left, right, freq := 0, 0, -1, map[int]int{} for left < len(nums) { if right+1 < len(nums) && freq[nums[right+1]] == 0 { freq[nums[right+1]]++ right++ } else { freq[nums[left]]-- left++ } sum ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value_test.go
leetcode/1695.Maximum-Erasure-Value/1695. Maximum Erasure Value_test.go
package leetcode import ( "fmt" "testing" ) type question1695 struct { para1695 ans1695 } // para 是参数 // one 代表第一个参数 type para1695 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1695 struct { one int } func Test_Problem1695(t *testing.T) { qs := []question1695{ { para1695{[]int{4, 2, 4, 5, 6...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2180.Count-Integers-With-Even-Digit-Sum/2180. Count Integers With Even Digit Sum.go
leetcode/2180.Count-Integers-With-Even-Digit-Sum/2180. Count Integers With Even Digit Sum.go
package leetcode func countEven(num int) int { count := 0 for i := 1; i <= num; i++ { if addSum(i)%2 == 0 { count++ } } return count } func addSum(num int) int { sum := 0 tmp := num for tmp != 0 { sum += tmp % 10 tmp = tmp / 10 } return sum }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2180.Count-Integers-With-Even-Digit-Sum/2180. Count Integers With Even Digit Sum_test.go
leetcode/2180.Count-Integers-With-Even-Digit-Sum/2180. Count Integers With Even Digit Sum_test.go
package leetcode import ( "fmt" "testing" ) type question2180 struct { para2180 ans2180 } // para 是参数 // one 代表第一个参数 type para2180 struct { target int } // ans 是答案 // one 代表第一个答案 type ans2180 struct { one int } func Test_Problem1(t *testing.T) { qs := []question2180{ { para2180{4}, ans2180{2}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1738.Find-Kth-Largest-XOR-Coordinate-Value/1738. Find Kth Largest XOR Coordinate Value.go
leetcode/1738.Find-Kth-Largest-XOR-Coordinate-Value/1738. Find Kth Largest XOR Coordinate Value.go
package leetcode import "sort" // 解法一 压缩版的前缀和 func kthLargestValue(matrix [][]int, k int) int { if len(matrix) == 0 || len(matrix[0]) == 0 { return 0 } res, prefixSum := make([]int, 0, len(matrix)*len(matrix[0])), make([]int, len(matrix[0])) for i := range matrix { line := 0 for j, v := range matrix[i] { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1738.Find-Kth-Largest-XOR-Coordinate-Value/1738. Find Kth Largest XOR Coordinate Value_test.go
leetcode/1738.Find-Kth-Largest-XOR-Coordinate-Value/1738. Find Kth Largest XOR Coordinate Value_test.go
package leetcode import ( "fmt" "testing" ) type question1738 struct { para1738 ans1738 } // para 是参数 // one 代表第一个参数 type para1738 struct { matrix [][]int k int } // ans 是答案 // one 代表第一个答案 type ans1738 struct { one int } func Test_Problem1738(t *testing.T) { qs := []question1738{ { para1738{[][...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0496.Next-Greater-Element-I/496. Next Greater Element I.go
leetcode/0496.Next-Greater-Element-I/496. Next Greater Element I.go
package leetcode func nextGreaterElement(nums1 []int, nums2 []int) []int { if len(nums1) == 0 || len(nums2) == 0 { return []int{} } res, reocrd := []int{}, map[int]int{} for i, v := range nums2 { reocrd[v] = i } for i := 0; i < len(nums1); i++ { flag := false for j := reocrd[nums1[i]]; j < len(nums2); j+...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0496.Next-Greater-Element-I/496. Next Greater Element I_test.go
leetcode/0496.Next-Greater-Element-I/496. Next Greater Element I_test.go
package leetcode import ( "fmt" "testing" ) type question496 struct { para496 ans496 } // para 是参数 // one 代表第一个参数 type para496 struct { one []int another []int } // ans 是答案 // one 代表第一个答案 type ans496 struct { one []int } func Test_Problem496(t *testing.T) { qs := []question496{ { para496{[]int{4...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0173.Binary-Search-Tree-Iterator/173. Binary Search Tree Iterator.go
leetcode/0173.Binary-Search-Tree-Iterator/173. Binary Search Tree Iterator.go
package leetcode import ( "container/heap" "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 * } */ // BSTIterator define type BSTI...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0173.Binary-Search-Tree-Iterator/173. Binary Search Tree Iterator_test.go
leetcode/0173.Binary-Search-Tree-Iterator/173. Binary Search Tree Iterator_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) func Test_Problem173(t *testing.T) { root := structures.Ints2TreeNode([]int{9, 7, 15, 3, structures.NULL, structures.NULL, 20}) obj := Constructor173(root) fmt.Printf("obj = %v\n", obj) param1 := obj.Next() fmt.Printf("...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1283.Find-the-Smallest-Divisor-Given-a-Threshold/1283. Find the Smallest Divisor Given a Threshold_test.go
leetcode/1283.Find-the-Smallest-Divisor-Given-a-Threshold/1283. Find the Smallest Divisor Given a Threshold_test.go
package leetcode import ( "fmt" "testing" ) type question1283 struct { para1283 ans1283 } // para 是参数 // one 代表第一个参数 type para1283 struct { nums []int threshold int } // ans 是答案 // one 代表第一个答案 type ans1283 struct { one int } func Test_Problem1283(t *testing.T) { qs := []question1283{ { para1283...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1283.Find-the-Smallest-Divisor-Given-a-Threshold/1283. Find the Smallest Divisor Given a Threshold.go
leetcode/1283.Find-the-Smallest-Divisor-Given-a-Threshold/1283. Find the Smallest Divisor Given a Threshold.go
package leetcode func smallestDivisor(nums []int, threshold int) int { low, high := 1, 1000000 for low < high { mid := low + (high-low)>>1 if calDivisor(nums, mid, threshold) { high = mid } else { low = mid + 1 } } return low } func calDivisor(nums []int, mid, threshold int) bool { sum := 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/0690.Employee-Importance/690. Employee Importance.go
leetcode/0690.Employee-Importance/690. Employee Importance.go
package leetcode type Employee struct { Id int Importance int Subordinates []int } func getImportance(employees []*Employee, id int) int { m, queue, res := map[int]*Employee{}, []int{id}, 0 for _, e := range employees { m[e.Id] = e } for len(queue) > 0 { e := m[queue[0]] queue = queue[1:] i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0690.Employee-Importance/690. Employee Importance_test.go
leetcode/0690.Employee-Importance/690. Employee Importance_test.go
package leetcode import ( "fmt" "testing" ) type question690 struct { para690 ans690 } // para 是参数 // one 代表第一个参数 type para690 struct { employees []*Employee id int } // ans 是答案 // one 代表第一个答案 type ans690 struct { one int } func Test_Problem690(t *testing.T) { qs := []question690{ { para690{[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0075.Sort-Colors/75. Sort Colors_test.go
leetcode/0075.Sort-Colors/75. Sort Colors_test.go
package leetcode import ( "fmt" "testing" ) type question75 struct { para75 ans75 } // para 是参数 // one 代表第一个参数 type para75 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans75 struct { one []int } func Test_Problem75(t *testing.T) { qs := []question75{ { para75{[]int{}}, ans75{[]int{}}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0075.Sort-Colors/75. Sort Colors.go
leetcode/0075.Sort-Colors/75. Sort Colors.go
package leetcode func sortColors(nums []int) { zero, one := 0, 0 for i, n := range nums { nums[i] = 2 if n <= 1 { nums[one] = 1 one++ } if n == 0 { nums[zero] = 0 zero++ } } }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0328.Odd-Even-Linked-List/328. Odd Even Linked List.go
leetcode/0328.Odd-Even-Linked-List/328. Odd Even 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 oddEvenList(head *ListNode) *ListNode { oddHead := &ListNode{Val: 0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0328.Odd-Even-Linked-List/328. Odd Even Linked List_test.go
leetcode/0328.Odd-Even-Linked-List/328. Odd Even Linked List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question328 struct { para328 ans328 } // para 是参数 // one 代表第一个参数 type para328 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans328 struct { one []int } func Test_Problem328(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/0677.Map-Sum-Pairs/677. Map Sum Pairs.go
leetcode/0677.Map-Sum-Pairs/677. Map Sum Pairs.go
package leetcode type MapSum struct { keys map[string]int } /** Initialize your data structure here. */ func Constructor() MapSum { return MapSum{make(map[string]int)} } func (this *MapSum) Insert(key string, val int) { this.keys[key] = val } func (this *MapSum) Sum(prefix string) int { prefixAsRunes, res := []...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0677.Map-Sum-Pairs/677. Map Sum Pairs_test.go
leetcode/0677.Map-Sum-Pairs/677. Map Sum Pairs_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem677(t *testing.T) { obj := Constructor() fmt.Printf("obj = %v\n", obj) obj.Insert("apple", 3) fmt.Printf("obj = %v\n", obj) fmt.Printf("obj.sum = %v\n", obj.Sum("ap")) obj.Insert("app", 2) fmt.Printf("obj = %v\n", obj) fmt.Printf("obj.sum = %v\n",...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0478.Generate-Random-Point-in-a-Circle/478. Generate Random Point in a Circle_test.go
leetcode/0478.Generate-Random-Point-in-a-Circle/478. Generate Random Point in a Circle_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem478(t *testing.T) { obj := Constructor(1, 0, 0) fmt.Printf("RandPoint() = %v\n", obj.RandPoint()) fmt.Printf("RandPoint() = %v\n", obj.RandPoint()) fmt.Printf("RandPoint() = %v\n", obj.RandPoint()) obj = Constructor(10, 5, -7.5) fmt.Printf("RandPoi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0478.Generate-Random-Point-in-a-Circle/478. Generate Random Point in a Circle.go
leetcode/0478.Generate-Random-Point-in-a-Circle/478. Generate Random Point in a Circle.go
package leetcode import ( "math" "math/rand" "time" ) type Solution struct { r float64 x float64 y float64 } func Constructor(radius float64, x_center float64, y_center float64) Solution { rand.Seed(time.Now().UnixNano()) return Solution{radius, x_center, y_center} } func (this *Solution) RandPoint() []floa...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0373.Find-K-Pairs-with-Smallest-Sums/373. Find K Pairs with Smallest Sums_test.go
leetcode/0373.Find-K-Pairs-with-Smallest-Sums/373. Find K Pairs with Smallest Sums_test.go
package leetcode import ( "fmt" "testing" ) type question373 struct { para373 ans373 } // para 是参数 // one 代表第一个参数 type para373 struct { nums1 []int nums2 []int k int } // ans 是答案 // one 代表第一个答案 type ans373 struct { one [][]int } func Test_Problem373(t *testing.T) { qs := []question373{ { para37...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0373.Find-K-Pairs-with-Smallest-Sums/373. Find K Pairs with Smallest Sums.go
leetcode/0373.Find-K-Pairs-with-Smallest-Sums/373. Find K Pairs with Smallest Sums.go
package leetcode import ( "container/heap" "sort" ) // 解法一 优先队列 func kSmallestPairs(nums1 []int, nums2 []int, k int) [][]int { result, h := [][]int{}, &minHeap{} if len(nums1) == 0 || len(nums2) == 0 || k == 0 { return result } if len(nums1)*len(nums2) < k { k = len(nums1) * len(nums2) } heap.Init(h) for...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0733.Flood-Fill/733. Flood Fill_test.go
leetcode/0733.Flood-Fill/733. Flood Fill_test.go
package leetcode import ( "fmt" "testing" ) type question733 struct { para733 ans733 } // para 是参数 // one 代表第一个参数 type para733 struct { one [][]int sr int sc int c int } // ans 是答案 // one 代表第一个答案 type ans733 struct { one [][]int } func Test_Problem733(t *testing.T) { qs := []question733{ { par...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0733.Flood-Fill/733. Flood Fill.go
leetcode/0733.Flood-Fill/733. Flood Fill.go
package leetcode var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } func floodFill(image [][]int, sr int, sc int, newColor int) [][]int { color := image[sr][sc] if newColor == color { return image } dfs733(image, sr, sc, newColor) return image } func dfs733(image [][]int, x, y int, newColor int) { if...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1054.Distant-Barcodes/1054. Distant Barcodes.go
leetcode/1054.Distant-Barcodes/1054. Distant Barcodes.go
package leetcode import "sort" func rearrangeBarcodes(barcodes []int) []int { bfs := barcodesFrequencySort(barcodes) if len(bfs) == 0 { return []int{} } res := []int{} j := (len(bfs)-1)/2 + 1 for i := 0; i <= (len(bfs)-1)/2; i++ { res = append(res, bfs[i]) if j < len(bfs) { res = append(res, bfs[j]) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1054.Distant-Barcodes/1054. Distant Barcodes_test.go
leetcode/1054.Distant-Barcodes/1054. Distant Barcodes_test.go
package leetcode import ( "fmt" "testing" ) type question1054 struct { para1054 ans1054 } // para 是参数 // one 代表第一个参数 type para1054 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1054 struct { one []int } func Test_Problem1054(t *testing.T) { qs := []question1054{ { para1054{[]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/1306.Jump-Game-III/1306. Jump Game III.go
leetcode/1306.Jump-Game-III/1306. Jump Game III.go
package leetcode func canReach(arr []int, start int) bool { if start >= 0 && start < len(arr) && arr[start] < len(arr) { jump := arr[start] arr[start] += len(arr) return jump == 0 || canReach(arr, start+jump) || canReach(arr, start-jump) } return false }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1306.Jump-Game-III/1306. Jump Game III_test.go
leetcode/1306.Jump-Game-III/1306. Jump Game III_test.go
package leetcode import ( "fmt" "testing" ) type question1306 struct { para1306 ans1306 } // para 是参数 // one 代表第一个参数 type para1306 struct { arr []int start int } // ans 是答案 // one 代表第一个答案 type ans1306 struct { one bool } func Test_Problem1306(t *testing.T) { qs := []question1306{ { para1306{[]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0368.Largest-Divisible-Subset/368. Largest Divisible Subset.go
leetcode/0368.Largest-Divisible-Subset/368. Largest Divisible Subset.go
package leetcode import "sort" func largestDivisibleSubset(nums []int) []int { sort.Ints(nums) dp, res := make([]int, len(nums)), []int{} for i := range dp { dp[i] = 1 } maxSize, maxVal := 1, 1 for i := 1; i < len(nums); i++ { for j, v := range nums[:i] { if nums[i]%v == 0 && dp[j]+1 > dp[i] { dp[i] ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0368.Largest-Divisible-Subset/368. Largest Divisible Subset_test.go
leetcode/0368.Largest-Divisible-Subset/368. Largest Divisible Subset_test.go
package leetcode import ( "fmt" "testing" ) type question368 struct { para368 ans368 } // para 是参数 // one 代表第一个参数 type para368 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans368 struct { one []int } func Test_Problem368(t *testing.T) { qs := []question368{ { para368{[]int{1, 2, 3}}, ans368...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1009.Complement-of-Base-10-Integer/1009. Complement of Base 10 Integer.go
leetcode/1009.Complement-of-Base-10-Integer/1009. Complement of Base 10 Integer.go
package leetcode func bitwiseComplement(n int) int { mask := 1 for mask < n { mask = (mask << 1) + 1 } return mask ^ n }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1009.Complement-of-Base-10-Integer/1009. Complement of Base 10 Integer_test.go
leetcode/1009.Complement-of-Base-10-Integer/1009. Complement of Base 10 Integer_test.go
package leetcode import ( "fmt" "testing" ) type question1009 struct { para1009 ans1009 } // para 是参数 // one 代表第一个参数 type para1009 struct { n int } // ans 是答案 // one 代表第一个答案 type ans1009 struct { one int } func Test_Problem1009(t *testing.T) { qs := []question1009{ { para1009{5}, ans1009{2}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1302.Deepest-Leaves-Sum/1302. Deepest Leaves Sum_test.go
leetcode/1302.Deepest-Leaves-Sum/1302. Deepest Leaves Sum_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1302 struct { para1302 ans1302 } // para 是参数 // one 代表第一个参数 type para1302 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1302 struct { one int } func Test_Problem1302(t *testing.T) { qs := []ques...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1302.Deepest-Leaves-Sum/1302. Deepest Leaves Sum.go
leetcode/1302.Deepest-Leaves-Sum/1302. Deepest Leaves Sum.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 deepestLeavesSum(root *TreeNode) int { maxLev...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0623.Add-One-Row-to-Tree/623. Add One Row to Tree_test.go
leetcode/0623.Add-One-Row-to-Tree/623. Add One Row to Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question623 struct { para623 ans623 } // para 是参数 // one 代表第一个参数 type para623 struct { one []int v int d int } // ans 是答案 // one 代表第一个答案 type ans623 struct { one []int } func Test_Problem623(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/0623.Add-One-Row-to-Tree/623. Add One Row to Tree.go
leetcode/0623.Add-One-Row-to-Tree/623. Add One Row to 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 addOneRow(root *TreeNode, v int, d int) *TreeN...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0475.Heaters/475. Heaters.go
leetcode/0475.Heaters/475. Heaters.go
package leetcode import ( "math" "sort" ) func findRadius(houses []int, heaters []int) int { minRad := 0 sort.Ints(heaters) for _, house := range houses { // 遍历房子的坐标,维护 heaters 的最小半径 heater := findClosestHeater(house, heaters) rad := heater - house if rad < 0 { rad = -rad } if rad > minRad { mi...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0475.Heaters/475. Heaters_test.go
leetcode/0475.Heaters/475. Heaters_test.go
package leetcode import ( "fmt" "testing" ) type question475 struct { para475 ans475 } // para 是参数 // one 代表第一个参数 type para475 struct { houses []int heaters []int } // ans 是答案 // one 代表第一个答案 type ans475 struct { one int } func Test_Problem475(t *testing.T) { qs := []question475{ { para475{[]int{1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1681.Minimum-Incompatibility/1681. Minimum Incompatibility.go
leetcode/1681.Minimum-Incompatibility/1681. Minimum Incompatibility.go
package leetcode import ( "math" "sort" ) func minimumIncompatibility(nums []int, k int) int { sort.Ints(nums) eachSize, counts := len(nums)/k, make([]int, len(nums)+1) for i := range nums { counts[nums[i]]++ if counts[nums[i]] > k { return -1 } } orders := []int{} for i := range counts { orders = ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1681.Minimum-Incompatibility/1681. Minimum Incompatibility_test.go
leetcode/1681.Minimum-Incompatibility/1681. Minimum Incompatibility_test.go
package leetcode import ( "fmt" "testing" ) type question1681 struct { para1681 ans1681 } // para 是参数 // one 代表第一个参数 type para1681 struct { nums []int k int } // ans 是答案 // one 代表第一个答案 type ans1681 struct { one int } func Test_Problem1681(t *testing.T) { qs := []question1681{ { para1681{[]int{1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2169.Count-Operations-to-Obtain-Zero/2169. Count Operations to Obtain Zero.go
leetcode/2169.Count-Operations-to-Obtain-Zero/2169. Count Operations to Obtain Zero.go
package leetcode func countOperations(num1 int, num2 int) int { res := 0 for num1 != 0 && num2 != 0 { if num1 >= num2 { num1 -= num2 } else { num2 -= num1 } res++ } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2169.Count-Operations-to-Obtain-Zero/2169. Count Operations to Obtain Zero_test.go
leetcode/2169.Count-Operations-to-Obtain-Zero/2169. Count Operations to Obtain Zero_test.go
package leetcode import ( "fmt" "testing" ) type question2169 struct { para2169 ans2169 } // para 是参数 // one 代表第一个参数 type para2169 struct { num1 int num2 int } // ans 是答案 // one 代表第一个答案 type ans2169 struct { one int } func Test_Problem2169(t *testing.T) { qs := []question2169{ { para2169{2, 3}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1608.Special-Array-With-X-Elements-Greater-Than-or-Equal-X/1608. Special Array With X Elements Greater Than or Equal X_test.go
leetcode/1608.Special-Array-With-X-Elements-Greater-Than-or-Equal-X/1608. Special Array With X Elements Greater Than or Equal X_test.go
package leetcode import ( "fmt" "testing" ) type question1608 struct { para1608 ans1608 } // para 是参数 // one 代表第一个参数 type para1608 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1608 struct { one int } func Test_Problem1608(t *testing.T) { qs := []question1608{ { para1608{[]int{3, 5}}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1608.Special-Array-With-X-Elements-Greater-Than-or-Equal-X/1608. Special Array With X Elements Greater Than or Equal X.go
leetcode/1608.Special-Array-With-X-Elements-Greater-Than-or-Equal-X/1608. Special Array With X Elements Greater Than or Equal X.go
package leetcode import "sort" func specialArray(nums []int) int { sort.Ints(nums) x := len(nums) for _, num := range nums { if num >= x { return x } x-- if num >= x { return -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/0206.Reverse-Linked-List/206. Reverse Linked List_test.go
leetcode/0206.Reverse-Linked-List/206. Reverse Linked List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question206 struct { para206 ans206 } // para 是参数 // one 代表第一个参数 type para206 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans206 struct { one []int } func Test_Problem206(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/0206.Reverse-Linked-List/206. Reverse Linked List.go
leetcode/0206.Reverse-Linked-List/206. Reverse 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 reverseList(head *ListNode) *ListNode { var behind *ListNode for h...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown/309. Best Time to Buy and Sell Stock with Cooldown_test.go
leetcode/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown/309. Best Time to Buy and Sell Stock with Cooldown_test.go
package leetcode import ( "fmt" "testing" ) type question309 struct { para309 ans309 } // para 是参数 // one 代表第一个参数 type para309 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans309 struct { one int } func Test_Problem309(t *testing.T) { qs := []question309{ { para309{[]int{}}, ans309{0}, },...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown/309. Best Time to Buy and Sell Stock with Cooldown.go
leetcode/0309.Best-Time-to-Buy-and-Sell-Stock-with-Cooldown/309. Best Time to Buy and Sell Stock with Cooldown.go
package leetcode import ( "math" ) // 解法一 DP func maxProfit309(prices []int) int { if len(prices) <= 1 { return 0 } buy, sell := make([]int, len(prices)), make([]int, len(prices)) for i := range buy { buy[i] = math.MinInt64 } buy[0] = -prices[0] buy[1] = max(buy[0], -prices[1]) sell[1] = max(sell[0], buy...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0228.Summary-Ranges/228. Summary Ranges.go
leetcode/0228.Summary-Ranges/228. Summary Ranges.go
package leetcode import ( "strconv" ) func summaryRanges(nums []int) (ans []string) { for i, n := 0, len(nums); i < n; { left := i for i++; i < n && nums[i-1]+1 == nums[i]; i++ { } s := strconv.Itoa(nums[left]) if left != i-1 { s += "->" + strconv.Itoa(nums[i-1]) } ans = append(ans, s) } return }...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0228.Summary-Ranges/228. Summary Ranges_test.go
leetcode/0228.Summary-Ranges/228. Summary Ranges_test.go
package leetcode import ( "fmt" "testing" ) type question228 struct { para228 ans228 } // para 是参数 // one 代表第一个参数 type para228 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans228 struct { ans []string } func Test_Problem228(t *testing.T) { qs := []question228{ { para228{[]int{0, 1, 2, 4, 5, 7...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1004.Max-Consecutive-Ones-III/1004. Max Consecutive Ones III_test.go
leetcode/1004.Max-Consecutive-Ones-III/1004. Max Consecutive Ones III_test.go
package leetcode import ( "fmt" "testing" ) type question1004 struct { para1004 ans1004 } // para 是参数 // one 代表第一个参数 type para1004 struct { s []int k int } // ans 是答案 // one 代表第一个答案 type ans1004 struct { one int } func Test_Problem1004(t *testing.T) { qs := []question1004{ { para1004{[]int{1, 1, 1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1004.Max-Consecutive-Ones-III/1004. Max Consecutive Ones III.go
leetcode/1004.Max-Consecutive-Ones-III/1004. Max Consecutive Ones III.go
package leetcode func longestOnes(A []int, K int) int { res, left, right := 0, 0, 0 for left < len(A) { if right < len(A) && ((A[right] == 0 && K > 0) || A[right] == 1) { if A[right] == 0 { K-- } right++ } else { if K == 0 || (right == len(A) && K > 0) { res = max(res, right-left) } if ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0055.Jump-Game/55. Jump Game_test.go
leetcode/0055.Jump-Game/55. Jump Game_test.go
package leetcode import ( "fmt" "testing" ) type question55 struct { para55 ans55 } // para 是参数 // one 代表第一个参数 type para55 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans55 struct { one bool } func Test_Problem55(t *testing.T) { qs := []question55{ { para55{[]int{2, 3, 1, 1, 4}}, ans55{tru...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0055.Jump-Game/55. Jump Game.go
leetcode/0055.Jump-Game/55. Jump Game.go
package leetcode func canJump(nums []int) bool { n := len(nums) if n == 0 { return false } if n == 1 { return true } maxJump := 0 for i, v := range nums { if i > maxJump { return false } maxJump = max(maxJump, i+v) } return true } 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/0992.Subarrays-with-K-Different-Integers/992. Subarrays with K Different Integers.go
leetcode/0992.Subarrays-with-K-Different-Integers/992. Subarrays with K Different Integers.go
package leetcode func subarraysWithKDistinct(A []int, K int) int { return subarraysWithKDistinctSlideWindow(A, K) - subarraysWithKDistinctSlideWindow(A, K-1) } func subarraysWithKDistinctSlideWindow(A []int, K int) int { left, right, counter, res, freq := 0, 0, K, 0, map[int]int{} for right = 0; right < len(A); ri...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0992.Subarrays-with-K-Different-Integers/992. Subarrays with K Different Integers_test.go
leetcode/0992.Subarrays-with-K-Different-Integers/992. Subarrays with K Different Integers_test.go
package leetcode import ( "fmt" "testing" ) type question992 struct { para992 ans992 } // para 是参数 // one 代表第一个参数 type para992 struct { one []int k int } // ans 是答案 // one 代表第一个答案 type ans992 struct { one int } func Test_Problem992(t *testing.T) { qs := []question992{ { para992{[]int{1, 1, 1, 1, 1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0037.Sudoku-Solver/37. Sudoku Solver_test.go
leetcode/0037.Sudoku-Solver/37. Sudoku Solver_test.go
package leetcode import ( "fmt" "testing" ) type question37 struct { para37 ans37 } // para 是参数 // one 代表第一个参数 type para37 struct { s [][]byte } // ans 是答案 // one 代表第一个答案 type ans37 struct { s [][]byte } func Test_Problem37(t *testing.T) { qs := []question37{ { para37{[][]byte{ {'5', '3', '.', '....
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0037.Sudoku-Solver/37. Sudoku Solver.go
leetcode/0037.Sudoku-Solver/37. Sudoku Solver.go
package leetcode type position struct { x int y int } func solveSudoku(board [][]byte) { pos, find := []position{}, false for i := 0; i < len(board); i++ { for j := 0; j < len(board[0]); j++ { if board[i][j] == '.' { pos = append(pos, position{x: i, y: j}) } } } putSudoku(&board, pos, 0, &find) } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0377.Combination-Sum-IV/377. Combination Sum IV_test.go
leetcode/0377.Combination-Sum-IV/377. Combination Sum IV_test.go
package leetcode import ( "fmt" "testing" ) type question377 struct { para377 ans377 } // para 是参数 // one 代表第一个参数 type para377 struct { n []int k int } // ans 是答案 // one 代表第一个答案 type ans377 struct { one int } func Test_Problem377(t *testing.T) { qs := []question377{ { para377{[]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/0377.Combination-Sum-IV/377. Combination Sum IV.go
leetcode/0377.Combination-Sum-IV/377. Combination Sum IV.go
package leetcode func combinationSum4(nums []int, target int) int { dp := make([]int, target+1) dp[0] = 1 for i := 1; i <= target; i++ { for _, num := range nums { if i-num >= 0 { dp[i] += dp[i-num] } } } return dp[target] } // 暴力解法超时 func combinationSum41(nums []int, target int) int { if len(nums...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0916.Word-Subsets/916. Word Subsets_test.go
leetcode/0916.Word-Subsets/916. Word Subsets_test.go
package leetcode import ( "fmt" "testing" ) type question916 struct { para916 ans916 } // para 是参数 // one 代表第一个参数 type para916 struct { A []string B []string } // ans 是答案 // one 代表第一个答案 type ans916 struct { one []string } func Test_Problem916(t *testing.T) { qs := []question916{ { para916{[]string{"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0916.Word-Subsets/916. Word Subsets.go
leetcode/0916.Word-Subsets/916. Word Subsets.go
package leetcode func wordSubsets(A []string, B []string) []string { var counter [26]int for _, b := range B { var m [26]int for _, c := range b { j := c - 'a' m[j]++ } for i := 0; i < 26; i++ { if m[i] > counter[i] { counter[i] = m[i] } } } var res []string for _, a := range A { var m...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1600.Throne-Inheritance/1600. Throne Inheritance.go
leetcode/1600.Throne-Inheritance/1600. Throne Inheritance.go
package leetcode type ThroneInheritance struct { king string edges map[string][]string dead map[string]bool } func Constructor(kingName string) (t ThroneInheritance) { return ThroneInheritance{kingName, map[string][]string{}, map[string]bool{}} } func (t *ThroneInheritance) Birth(parentName, childName string) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1600.Throne-Inheritance/1600. Throne Inheritance_test.go
leetcode/1600.Throne-Inheritance/1600. Throne Inheritance_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem1600(t *testing.T) { obj := Constructor("king") fmt.Printf("obj = %v\n", obj) obj.Birth("king", "andy") fmt.Printf("obj = %v\n", obj) obj.Birth("king", "bob") fmt.Printf("obj = %v\n", obj) obj.Birth("king", "catherine") fmt.Printf("obj = %v\n", ob...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0030.Substring-with-Concatenation-of-All-Words/30. Substring with Concatenation of All Words_test.go
leetcode/0030.Substring-with-Concatenation-of-All-Words/30. Substring with Concatenation of All Words_test.go
package leetcode import ( "fmt" "testing" ) type question30 struct { para30 ans30 } // para 是参数 // one 代表第一个参数 type para30 struct { one string two []string } // ans 是答案 // one 代表第一个答案 type ans30 struct { one []int } func Test_Problem30(t *testing.T) { qs := []question30{ { para30{"aaaaaaaa", []strin...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0030.Substring-with-Concatenation-of-All-Words/30. Substring with Concatenation of All Words.go
leetcode/0030.Substring-with-Concatenation-of-All-Words/30. Substring with Concatenation of All Words.go
package leetcode func findSubstring(s string, words []string) []int { if len(words) == 0 { return []int{} } res := []int{} counter := map[string]int{} for _, w := range words { counter[w]++ } length, totalLen, tmpCounter := len(words[0]), len(words[0])*len(words), copyMap(counter) for i, start := 0, 0; i <...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0064.Minimum-Path-Sum/64. Minimum Path Sum.go
leetcode/0064.Minimum-Path-Sum/64. Minimum Path Sum.go
package leetcode // 解法一 原地 DP,无辅助空间 func minPathSum(grid [][]int) int { m, n := len(grid), len(grid[0]) for i := 1; i < m; i++ { grid[i][0] += grid[i-1][0] } for j := 1; j < n; j++ { grid[0][j] += grid[0][j-1] } for i := 1; i < m; i++ { for j := 1; j < n; j++ { grid[i][j] += min(grid[i-1][j], grid[i][j-...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0064.Minimum-Path-Sum/64. Minimum Path Sum_test.go
leetcode/0064.Minimum-Path-Sum/64. Minimum Path Sum_test.go
package leetcode import ( "fmt" "testing" ) type question64 struct { para64 ans64 } // para 是参数 // one 代表第一个参数 type para64 struct { og [][]int } // ans 是答案 // one 代表第一个答案 type ans64 struct { one int } func Test_Problem64(t *testing.T) { qs := []question64{ { para64{[][]int{ {1, 3, 1}, {1, 5, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0231.Power-of-Two/231. Power of Two_test.go
leetcode/0231.Power-of-Two/231. Power of Two_test.go
package leetcode import ( "fmt" "testing" ) type question231 struct { para231 ans231 } // para 是参数 // one 代表第一个参数 type para231 struct { one int } // ans 是答案 // one 代表第一个答案 type ans231 struct { one bool } func Test_Problem231(t *testing.T) { qs := []question231{ { para231{1}, ans231{true}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0231.Power-of-Two/231. Power of Two.go
leetcode/0231.Power-of-Two/231. Power of Two.go
package leetcode // 解法一 二进制位操作法 func isPowerOfTwo(num int) bool { return (num > 0 && ((num & (num - 1)) == 0)) } // 解法二 数论 func isPowerOfTwo1(num int) bool { return num > 0 && (1073741824%num == 0) } // 解法三 打表法 func isPowerOfTwo2(num int) bool { allPowerOfTwoMap := map[int]int{1: 1, 2: 2, 4: 4, 8: 8, 16: 16, 32: ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1696.Jump-Game-VI/1696. Jump Game VI.go
leetcode/1696.Jump-Game-VI/1696. Jump Game VI.go
package leetcode import ( "math" ) // 单调队列 func maxResult(nums []int, k int) int { dp := make([]int, len(nums)) dp[0] = nums[0] for i := 1; i < len(dp); i++ { dp[i] = math.MinInt32 } window := make([]int, k) for i := 1; i < len(nums); i++ { dp[i] = nums[i] + dp[window[0]] for len(window) > 0 && dp[window...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1696.Jump-Game-VI/1696. Jump Game VI_test.go
leetcode/1696.Jump-Game-VI/1696. Jump Game VI_test.go
package leetcode import ( "fmt" "testing" ) type question1696 struct { para1696 ans1696 } // para 是参数 // one 代表第一个参数 type para1696 struct { nums []int k int } // ans 是答案 // one 代表第一个答案 type ans1696 struct { one int } func Test_Problem1696(t *testing.T) { qs := []question1696{ { para1696{[]int{1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1051.Height-Checker/1051. Height Checker.go
leetcode/1051.Height-Checker/1051. Height Checker.go
package leetcode import "sort" func heightChecker(heights []int) int { result, checker := 0, []int{} checker = append(checker, heights...) sort.Ints(checker) for i := 0; i < len(heights); i++ { if heights[i] != checker[i] { result++ } } return result }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1051.Height-Checker/1051. Height Checker_test.go
leetcode/1051.Height-Checker/1051. Height Checker_test.go
package leetcode import ( "fmt" "testing" ) type question1051 struct { para1051 ans1051 } // para 是参数 // one 代表第一个参数 type para1051 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1051 struct { one int } func Test_Problem1051(t *testing.T) { qs := []question1051{ { para1051{[]int{1, 1, 4, 2, 1,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0236.Lowest-Common-Ancestor-of-a-Binary-Tree/236. Lowest Common Ancestor of a Binary Tree.go
leetcode/0236.Lowest-Common-Ancestor-of-a-Binary-Tree/236. Lowest Common Ancestor of a 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 lowestCommonAncestor236(root, p, q *TreeNode)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0236.Lowest-Common-Ancestor-of-a-Binary-Tree/236. Lowest Common Ancestor of a Binary Tree_test.go
leetcode/0236.Lowest-Common-Ancestor-of-a-Binary-Tree/236. Lowest Common Ancestor of a Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question236 struct { para236 ans236 } // para 是参数 // one 代表第一个参数 type para236 struct { one []int two []int thr []int } // ans 是答案 // one 代表第一个答案 type ans236 struct { one []int } func Test_Problem236(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/1123.Lowest-Common-Ancestor-of-Deepest-Leaves/1123. Lowest Common Ancestor of Deepest Leaves.go
leetcode/1123.Lowest-Common-Ancestor-of-Deepest-Leaves/1123. Lowest Common Ancestor of Deepest Leaves.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func lcaDeepestLeaves(root *TreeNode) *TreeNode { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1123.Lowest-Common-Ancestor-of-Deepest-Leaves/1123. Lowest Common Ancestor of Deepest Leaves_test.go
leetcode/1123.Lowest-Common-Ancestor-of-Deepest-Leaves/1123. Lowest Common Ancestor of Deepest Leaves_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1123 struct { para1123 ans1123 } // para 是参数 // one 代表第一个参数 type para1123 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1123 struct { one []int } func Test_Problem1123(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/1329.Sort-the-Matrix-Diagonally/1329. Sort the Matrix Diagonally_test.go
leetcode/1329.Sort-the-Matrix-Diagonally/1329. Sort the Matrix Diagonally_test.go
package leetcode import ( "fmt" "testing" ) type question1329 struct { para1329 ans1329 } // para 是参数 // one 代表第一个参数 type para1329 struct { mat [][]int } // ans 是答案 // one 代表第一个答案 type ans1329 struct { one [][]int } func Test_Problem1329(t *testing.T) { qs := []question1329{ { para1329{[][]int{{3, 3,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1329.Sort-the-Matrix-Diagonally/1329. Sort the Matrix Diagonally.go
leetcode/1329.Sort-the-Matrix-Diagonally/1329. Sort the Matrix Diagonally.go
package leetcode import ( "sort" ) func diagonalSort(mat [][]int) [][]int { m, n, diagonalsMap := len(mat), len(mat[0]), make(map[int][]int) for i := 0; i < m; i++ { for j := 0; j < n; j++ { diagonalsMap[i-j] = append(diagonalsMap[i-j], mat[i][j]) } } for _, v := range diagonalsMap { sort.Ints(v) } fo...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false