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/0258.Add-Digits/258. Add Digits_test.go
leetcode/0258.Add-Digits/258. Add Digits_test.go
package leetcode import ( "fmt" "testing" ) type question258 struct { para258 ans258 } // para 是参数 // one 代表第一个参数 type para258 struct { one int } // ans 是答案 // one 代表第一个答案 type ans258 struct { one int } func Test_Problem258(t *testing.T) { qs := []question258{ { para258{38}, ans258{2}, }, { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0258.Add-Digits/258. Add Digits.go
leetcode/0258.Add-Digits/258. Add Digits.go
package leetcode func addDigits(num int) int { for num > 9 { cur := 0 for num != 0 { cur += num % 10 num /= 10 } num = cur } return num }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0493.Reverse-Pairs/493. Reverse Pairs_test.go
leetcode/0493.Reverse-Pairs/493. Reverse Pairs_test.go
package leetcode import ( "fmt" "testing" ) type question493 struct { para493 ans493 } // para 是参数 // one 代表第一个参数 type para493 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans493 struct { one int } func Test_Problem493(t *testing.T) { qs := []question493{ { para493{[]int{1, 3, 2, 3, 1}}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0493.Reverse-Pairs/493. Reverse Pairs.go
leetcode/0493.Reverse-Pairs/493. Reverse Pairs.go
package leetcode import ( "sort" "github.com/halfrost/LeetCode-Go/template" ) // 解法一 归并排序 mergesort,时间复杂度 O(n log n) func reversePairs(nums []int) int { buf := make([]int, len(nums)) return mergesortCount(nums, buf) } func mergesortCount(nums, buf []int) int { if len(nums) <= 1 { return 0 } mid := (len(num...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0344.Reverse-String/344. Reverse String.go
leetcode/0344.Reverse-String/344. Reverse String.go
package leetcode func reverseString(s []byte) { for i, j := 0, len(s)-1; i < j; { s[i], s[j] = s[j], s[i] i++ j-- } }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0344.Reverse-String/344. Reverse String_test.go
leetcode/0344.Reverse-String/344. Reverse String_test.go
package leetcode import ( "fmt" "testing" ) type question344 struct { para344 ans344 } // para 是参数 // one 代表第一个参数 type para344 struct { one []byte } // ans 是答案 // one 代表第一个答案 type ans344 struct { one []byte } func Test_Problem344(t *testing.T) { qs := []question344{ { para344{[]byte{'h', 'e', 'l', 'l...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0947.Most-Stones-Removed-with-Same-Row-or-Column/947. Most Stones Removed with Same Row or Column.go
leetcode/0947.Most-Stones-Removed-with-Same-Row-or-Column/947. Most Stones Removed with Same Row or Column.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) func removeStones(stones [][]int) int { if len(stones) <= 1 { return 0 } uf, rowMap, colMap := template.UnionFind{}, map[int]int{}, map[int]int{} uf.Init(len(stones)) for i := 0; i < len(stones); i++ { if _, ok := rowMap[stones[i][0]]; o...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0947.Most-Stones-Removed-with-Same-Row-or-Column/947. Most Stones Removed with Same Row or Column_test.go
leetcode/0947.Most-Stones-Removed-with-Same-Row-or-Column/947. Most Stones Removed with Same Row or Column_test.go
package leetcode import ( "fmt" "testing" ) type question947 struct { para947 ans947 } // para 是参数 // one 代表第一个参数 type para947 struct { stones [][]int } // ans 是答案 // one 代表第一个答案 type ans947 struct { one int } func Test_Problem947(t *testing.T) { qs := []question947{ { para947{[][]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/0435.Non-overlapping-Intervals/435. Non-overlapping Intervals_test.go
leetcode/0435.Non-overlapping-Intervals/435. Non-overlapping Intervals_test.go
package leetcode import ( "fmt" "testing" ) type question435 struct { para435 ans435 } // para 是参数 // one 代表第一个参数 type para435 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans435 struct { one int } func Test_Problem435(t *testing.T) { qs := []question435{ { para435{[][]int{{1, 2}, {2, 3}, {3...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0435.Non-overlapping-Intervals/435. Non-overlapping Intervals.go
leetcode/0435.Non-overlapping-Intervals/435. Non-overlapping Intervals.go
package leetcode import ( "sort" ) // 解法一 DP O(n^2) 思路是仿造最长上升子序列的思路 func eraseOverlapIntervals(intervals [][]int) int { if len(intervals) == 0 { return 0 } sort.Sort(Intervals(intervals)) dp, res := make([]int, len(intervals)), 0 for i := range dp { dp[i] = 1 } for i := 1; i < len(intervals); i++ { for ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1028.Recover-a-Tree-From-Preorder-Traversal/1028. Recover a Tree From Preorder Traversal_test.go
leetcode/1028.Recover-a-Tree-From-Preorder-Traversal/1028. Recover a Tree From Preorder Traversal_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1028 struct { para1028 ans1028 } // para 是参数 // one 代表第一个参数 type para1028 struct { one string } // ans 是答案 // one 代表第一个答案 type ans1028 struct { one []int } func Test_Problem1028(t *testing.T) { qs := []q...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1028.Recover-a-Tree-From-Preorder-Traversal/1028. Recover a Tree From Preorder Traversal.go
leetcode/1028.Recover-a-Tree-From-Preorder-Traversal/1028. Recover a Tree From Preorder Traversal.go
package leetcode import ( "strconv" "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func recoverFromPreorder(S string) *Tr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0071.Simplify-Path/71. Simplify Path_test.go
leetcode/0071.Simplify-Path/71. Simplify Path_test.go
package leetcode import ( "fmt" "testing" ) type question71 struct { para71 ans71 } // para 是参数 // one 代表第一个参数 type para71 struct { s string } // ans 是答案 // one 代表第一个答案 type ans71 struct { one string } func Test_Problem71(t *testing.T) { qs := []question71{ { para71{"/.hidden"}, ans71{"/.hidden"},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0071.Simplify-Path/71. Simplify Path.go
leetcode/0071.Simplify-Path/71. Simplify Path.go
package leetcode import ( "path/filepath" "strings" ) // 解法一 func simplifyPath(path string) string { arr := strings.Split(path, "/") stack := make([]string, 0) var res string for i := 0; i < len(arr); i++ { cur := arr[i] //cur := strings.TrimSpace(arr[i]) 更加严谨的做法应该还要去掉末尾的空格 if cur == ".." { if len(stac...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0869.Reordered-Power-of-2/869. Reordered Power of 2_test.go
leetcode/0869.Reordered-Power-of-2/869. Reordered Power of 2_test.go
package leetcode import ( "fmt" "testing" ) type question869 struct { para869 ans869 } // para 是参数 // one 代表第一个参数 type para869 struct { n int } // ans 是答案 // one 代表第一个答案 type ans869 struct { one bool } func Test_Problem869(t *testing.T) { qs := []question869{ { para869{1}, ans869{true}, }, { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0869.Reordered-Power-of-2/869. Reordered Power of 2.go
leetcode/0869.Reordered-Power-of-2/869. Reordered Power of 2.go
package leetcode import "fmt" func reorderedPowerOf2(n int) bool { sample, i := fmt.Sprintf("%v", n), 1 for len(fmt.Sprintf("%v", i)) <= len(sample) { t := fmt.Sprintf("%v", i) if len(t) == len(sample) && isSame(t, sample) { return true } i = i << 1 } return false } func isSame(t, s string) bool { m ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0560.Subarray-Sum-Equals-K/560. Subarray Sum Equals K_test.go
leetcode/0560.Subarray-Sum-Equals-K/560. Subarray Sum Equals K_test.go
package leetcode import ( "fmt" "testing" ) type question560 struct { para560 ans560 } // para 是参数 // one 代表第一个参数 type para560 struct { nums []int k int } // ans 是答案 // one 代表第一个答案 type ans560 struct { one int } func Test_Problem560(t *testing.T) { qs := []question560{ { para560{[]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/0560.Subarray-Sum-Equals-K/560. Subarray Sum Equals K.go
leetcode/0560.Subarray-Sum-Equals-K/560. Subarray Sum Equals K.go
package leetcode func subarraySum(nums []int, k int) int { count, pre := 0, 0 m := map[int]int{} m[0] = 1 for i := 0; i < len(nums); i++ { pre += nums[i] if _, ok := m[pre-k]; ok { count += m[pre-k] } m[pre] += 1 } return count }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0318.Maximum-Product-of-Word-Lengths/318. Maximum Product of Word Lengths_test.go
leetcode/0318.Maximum-Product-of-Word-Lengths/318. Maximum Product of Word Lengths_test.go
package leetcode import ( "fmt" "testing" ) type question318 struct { para318 ans318 } // para 是参数 // one 代表第一个参数 type para318 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans318 struct { one int } func Test_Problem318(t *testing.T) { qs := []question318{ { para318{[]string{"abcw", "baz", "...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0318.Maximum-Product-of-Word-Lengths/318. Maximum Product of Word Lengths.go
leetcode/0318.Maximum-Product-of-Word-Lengths/318. Maximum Product of Word Lengths.go
package leetcode func maxProduct318(words []string) int { if words == nil || len(words) == 0 { return 0 } length, value, maxProduct := len(words), make([]int, len(words)), 0 for i := 0; i < length; i++ { tmp := words[i] value[i] = 0 for j := 0; j < len(tmp); j++ { value[i] |= 1 << (tmp[j] - 'a') } } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0396.Rotate-Function/396. Rotate Function_test.go
leetcode/0396.Rotate-Function/396. Rotate Function_test.go
package leetcode import ( "fmt" "testing" ) type question396 struct { para396 ans396 } // para 是参数 // one 代表第一个参数 type para396 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans396 struct { one int } func Test_Problem396(t *testing.T) { qs := []question396{ { para396{[]int{4, 3, 2, 6}}, ans396...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0396.Rotate-Function/396. Rotate Function.go
leetcode/0396.Rotate-Function/396. Rotate Function.go
package leetcode func maxRotateFunction(nums []int) int { n := len(nums) var sum, f int for i, num := range nums { sum += num f += i * num // F(0) } ans := f for i := 1; i < n; i++ { f += sum - n*nums[n-i] // F(i) = F(i-1) + sum - n*nums[n-i] if f > ans { ans = f } } return ans }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0066.Plus-One/66. Plus One.go
leetcode/0066.Plus-One/66. Plus One.go
package leetcode func plusOne(digits []int) []int { for i := len(digits) - 1; i >= 0; i-- { if digits[i] != 9 { digits[i]++ return digits } digits[i] = 0 } return append([]int{1}, digits...) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0066.Plus-One/66. Plus One_test.go
leetcode/0066.Plus-One/66. Plus One_test.go
package leetcode import ( "fmt" "testing" ) type question66 struct { para66 ans66 } // para 是参数 // one 代表第一个参数 type para66 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans66 struct { one []int } func Test_Problem66(t *testing.T) { qs := []question66{ { para66{[]int{1, 2, 3}}, ans66{[]int{1,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1091.Shortest-Path-in-Binary-Matrix/1091. Shortest Path in Binary Matrix.go
leetcode/1091.Shortest-Path-in-Binary-Matrix/1091. Shortest Path in Binary Matrix.go
package leetcode var dir = [][]int{ {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, } func shortestPathBinaryMatrix(grid [][]int) int { visited := make([][]bool, 0) for range make([]int, len(grid)) { visited = append(visited, make([]bool, len(grid[0]))) } dis := make([][]int, 0) f...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1091.Shortest-Path-in-Binary-Matrix/1091. Shortest Path in Binary Matrix_test.go
leetcode/1091.Shortest-Path-in-Binary-Matrix/1091. Shortest Path in Binary Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question1091 struct { para1091 ans1091 } // para 是参数 // one 代表第一个参数 type para1091 struct { grid [][]int } // ans 是答案 // one 代表第一个答案 type ans1091 struct { one int } func Test_Problem1091(t *testing.T) { qs := []question1091{ { para1091{[][]int{{0, 1}, {...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0009.Palindrome-Number/9. Palindrome Number.go
leetcode/0009.Palindrome-Number/9. Palindrome Number.go
package leetcode import "strconv" // 解法一 func isPalindrome(x int) bool { if x < 0 { return false } if x == 0 { return true } if x%10 == 0 { return false } arr := make([]int, 0, 32) for x > 0 { arr = append(arr, x%10) x = x / 10 } sz := len(arr) for i, j := 0, sz-1; i <= j; i, j = i+1, j-1 { if ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0009.Palindrome-Number/9. Palindrome Number_test.go
leetcode/0009.Palindrome-Number/9. Palindrome Number_test.go
package leetcode import ( "fmt" "testing" ) type question9 struct { para9 ans9 } // para 是参数 // one 代表第一个参数 type para9 struct { one int } // ans 是答案 // one 代表第一个答案 type ans9 struct { one bool } func Test_Problem9(t *testing.T) { qs := []question9{ { para9{121}, ans9{true}, }, { para9{-121}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1006.Clumsy-Factorial/1006. Clumsy Factorial_test.go
leetcode/1006.Clumsy-Factorial/1006. Clumsy Factorial_test.go
package leetcode import ( "fmt" "testing" ) type question1006 struct { para1006 ans1006 } // para 是参数 // one 代表第一个参数 type para1006 struct { N int } // ans 是答案 // one 代表第一个答案 type ans1006 struct { one int } func Test_Problem1006(t *testing.T) { qs := []question1006{ { para1006{4}, ans1006{7}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1006.Clumsy-Factorial/1006. Clumsy Factorial.go
leetcode/1006.Clumsy-Factorial/1006. Clumsy Factorial.go
package leetcode func clumsy(N int) int { res, count, tmp, flag := 0, 1, N, false for i := N - 1; i > 0; i-- { count = count % 4 switch count { case 1: tmp = tmp * i case 2: tmp = tmp / i case 3: res = res + tmp flag = true tmp = -1 res = res + i case 0: flag = false tmp = tmp * (...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0279.Perfect-Squares/279. Perfect Squares_test.go
leetcode/0279.Perfect-Squares/279. Perfect Squares_test.go
package leetcode import ( "fmt" "testing" ) type question279 struct { para279 ans279 } // para 是参数 // one 代表第一个参数 type para279 struct { n int } // ans 是答案 // one 代表第一个答案 type ans279 struct { one int } func Test_Problem279(t *testing.T) { qs := []question279{ { para279{13}, ans279{2}, }, { p...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0279.Perfect-Squares/279. Perfect Squares.go
leetcode/0279.Perfect-Squares/279. Perfect Squares.go
package leetcode import "math" func numSquares(n int) int { if isPerfectSquare(n) { return 1 } if checkAnswer4(n) { return 4 } for i := 1; i*i <= n; i++ { j := n - i*i if isPerfectSquare(j) { return 2 } } return 3 } // 判断是否为完全平方数 func isPerfectSquare(n int) bool { sq := int(math.Floor(math.Sqrt(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1631.Path-With-Minimum-Effort/1631. Path With Minimum Effort.go
leetcode/1631.Path-With-Minimum-Effort/1631. Path With Minimum Effort.go
package leetcode import ( "sort" "github.com/halfrost/LeetCode-Go/template" ) var dir = [4][2]int{ {0, 1}, {1, 0}, {0, -1}, {-1, 0}, } // 解法一 DFS + 二分 func minimumEffortPath(heights [][]int) int { n, m := len(heights), len(heights[0]) visited := make([][]bool, n) for i := range visited { visited[i] = mak...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1631.Path-With-Minimum-Effort/1631. Path With Minimum Effort_test.go
leetcode/1631.Path-With-Minimum-Effort/1631. Path With Minimum Effort_test.go
package leetcode import ( "fmt" "testing" ) type question1631 struct { para1631 ans1631 } // para 是参数 // one 代表第一个参数 type para1631 struct { heights [][]int } // ans 是答案 // one 代表第一个答案 type ans1631 struct { one int } func Test_Problem1631(t *testing.T) { qs := []question1631{ { para1631{[][]int{{1, 2,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1209.Remove-All-Adjacent-Duplicates-in-String-II/1209. Remove All Adjacent Duplicates in String II.go
leetcode/1209.Remove-All-Adjacent-Duplicates-in-String-II/1209. Remove All Adjacent Duplicates in String II.go
package leetcode // 解法一 stack func removeDuplicates(s string, k int) string { stack, arr := [][2]int{}, []byte{} for _, c := range s { i := int(c - 'a') if len(stack) > 0 && stack[len(stack)-1][0] == i { stack[len(stack)-1][1]++ if stack[len(stack)-1][1] == k { stack = stack[:len(stack)-1] } } els...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1209.Remove-All-Adjacent-Duplicates-in-String-II/1209. Remove All Adjacent Duplicates in String II_test.go
leetcode/1209.Remove-All-Adjacent-Duplicates-in-String-II/1209. Remove All Adjacent Duplicates in String II_test.go
package leetcode import ( "fmt" "testing" ) type question1209 struct { para1209 ans1209 } // para 是参数 // one 代表第一个参数 type para1209 struct { s string k int } // ans 是答案 // one 代表第一个答案 type ans1209 struct { one string } func Test_Problem1209(t *testing.T) { qs := []question1209{ // { // para1209{"abcd...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0039.Combination-Sum/39. Combination Sum_test.go
leetcode/0039.Combination-Sum/39. Combination Sum_test.go
package leetcode import ( "fmt" "testing" ) type question39 struct { para39 ans39 } // para 是参数 // one 代表第一个参数 type para39 struct { n []int k int } // ans 是答案 // one 代表第一个答案 type ans39 struct { one [][]int } func Test_Problem39(t *testing.T) { qs := []question39{ { para39{[]int{2, 3, 6, 7}, 7}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0039.Combination-Sum/39. Combination Sum.go
leetcode/0039.Combination-Sum/39. Combination Sum.go
package leetcode import "sort" func combinationSum(candidates []int, target int) [][]int { if len(candidates) == 0 { return [][]int{} } c, res := []int{}, [][]int{} sort.Ints(candidates) findcombinationSum(candidates, target, 0, c, &res) return res } func findcombinationSum(nums []int, target, index int, c [...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0897.Increasing-Order-Search-Tree/897. Increasing Order Search Tree_test.go
leetcode/0897.Increasing-Order-Search-Tree/897. Increasing Order Search Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question897 struct { para897 ans897 } // para 是参数 // one 代表第一个参数 type para897 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans897 struct { one []int } func Test_Problem897(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/0897.Increasing-Order-Search-Tree/897. Increasing Order Search Tree.go
leetcode/0897.Increasing-Order-Search-Tree/897. Increasing Order Search Tree.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ // 解法一 链表思想 func increasingBST(root *TreeNode) *Tr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0352.Data-Stream-as-Disjoint-Intervals/352.Data Stream as Disjoint Intervals_test.go
leetcode/0352.Data-Stream-as-Disjoint-Intervals/352.Data Stream as Disjoint Intervals_test.go
package leetcode import ( "fmt" "testing" ) type question352 struct { para352 ans352 } // para 是参数 type para352 struct { para string num int } // ans 是答案 type ans352 struct { ans [][]int } func Test_Problem352(t *testing.T) { qs := []question352{ { para352{"addNum", 1}, ans352{[][]int{{1, 1}}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0352.Data-Stream-as-Disjoint-Intervals/352.Data Stream as Disjoint Intervals.go
leetcode/0352.Data-Stream-as-Disjoint-Intervals/352.Data Stream as Disjoint Intervals.go
package leetcode import "sort" type SummaryRanges struct { nums []int mp map[int]int } func Constructor() SummaryRanges { return SummaryRanges{ nums: []int{}, mp: map[int]int{}, } } func (this *SummaryRanges) AddNum(val int) { if _, ok := this.mp[val]; !ok { this.mp[val] = 1 this.nums = append(this...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0394.Decode-String/394. Decode String_test.go
leetcode/0394.Decode-String/394. Decode String_test.go
package leetcode import ( "fmt" "testing" ) type question394 struct { para394 ans394 } // para 是参数 // one 代表第一个参数 type para394 struct { s string } // ans 是答案 // one 代表第一个答案 type ans394 struct { one string } func Test_Problem394(t *testing.T) { qs := []question394{ { para394{"10[a]"}, ans394{"aaaaa...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0394.Decode-String/394. Decode String.go
leetcode/0394.Decode-String/394. Decode String.go
package leetcode import ( "strconv" ) func decodeString(s string) string { stack, res := []string{}, "" for _, str := range s { if len(stack) == 0 || (len(stack) > 0 && str != ']') { stack = append(stack, string(str)) } else { tmp := "" for stack[len(stack)-1] != "[" { tmp = stack[len(stack)-1] + ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0845.Longest-Mountain-in-Array/845. Longest Mountain in Array.go
leetcode/0845.Longest-Mountain-in-Array/845. Longest Mountain in Array.go
package leetcode func longestMountain(A []int) int { left, right, res, isAscending := 0, 0, 0, true for left < len(A) { if right+1 < len(A) && ((isAscending == true && A[right+1] > A[left] && A[right+1] > A[right]) || (right != left && A[right+1] < A[right])) { if A[right+1] < A[right] { isAscending = false...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0845.Longest-Mountain-in-Array/845. Longest Mountain in Array_test.go
leetcode/0845.Longest-Mountain-in-Array/845. Longest Mountain in Array_test.go
package leetcode import ( "fmt" "testing" ) type question845 struct { para845 ans845 } // para 是参数 // one 代表第一个参数 type para845 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans845 struct { one int } func Test_Problem845(t *testing.T) { qs := []question845{ { para845{[]int{875, 884, 239, 731, 723...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0455.Assign-Cookies/455. Assign Cookies_test.go
leetcode/0455.Assign-Cookies/455. Assign Cookies_test.go
package leetcode import ( "fmt" "testing" ) type question455 struct { para455 ans455 } // para 是参数 // one 代表第一个参数 type para455 struct { g []int s []int } // ans 是答案 // one 代表第一个答案 type ans455 struct { one int } func Test_Problem455(t *testing.T) { qs := []question455{ { para455{[]int{1, 2, 3}, []int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0455.Assign-Cookies/455. Assign Cookies.go
leetcode/0455.Assign-Cookies/455. Assign Cookies.go
package leetcode import "sort" func findContentChildren(g []int, s []int) int { sort.Ints(g) sort.Ints(s) gi, si, res := 0, 0, 0 for gi < len(g) && si < len(s) { if s[si] >= g[gi] { res++ si++ gi++ } else { si++ } } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0968.Binary-Tree-Cameras/968. Binary Tree Cameras.go
leetcode/0968.Binary-Tree-Cameras/968. Binary Tree Cameras.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 * } */ type status int const ( isLeaf status = iota pa...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0968.Binary-Tree-Cameras/968. Binary Tree Cameras_test.go
leetcode/0968.Binary-Tree-Cameras/968. Binary Tree Cameras_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question968 struct { para968 ans968 } // para 是参数 // one 代表第一个参数 type para968 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans968 struct { one int } func Test_Problem968(t *testing.T) { qs := []question96...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0795.Number-of-Subarrays-with-Bounded-Maximum/795. Number of Subarrays with Bounded Maximum_test.go
leetcode/0795.Number-of-Subarrays-with-Bounded-Maximum/795. Number of Subarrays with Bounded Maximum_test.go
package leetcode import ( "fmt" "testing" ) type question795 struct { para795 ans795 } // para 是参数 // one 代表第一个参数 type para795 struct { nums []int left int right int } // ans 是答案 // one 代表第一个答案 type ans795 struct { one int } func Test_Problem795(t *testing.T) { qs := []question795{ { para795{[]in...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0795.Number-of-Subarrays-with-Bounded-Maximum/795. Number of Subarrays with Bounded Maximum.go
leetcode/0795.Number-of-Subarrays-with-Bounded-Maximum/795. Number of Subarrays with Bounded Maximum.go
package leetcode func numSubarrayBoundedMax(nums []int, left int, right int) int { return getAnswerPerBound(nums, right) - getAnswerPerBound(nums, left-1) } func getAnswerPerBound(nums []int, bound int) int { res, count := 0, 0 for _, num := range nums { if num <= bound { count++ } else { count = 0 } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0844.Backspace-String-Compare/844. Backspace String Compare_test.go
leetcode/0844.Backspace-String-Compare/844. Backspace String Compare_test.go
package leetcode import ( "fmt" "testing" ) type question844 struct { para844 ans844 } // para 是参数 // one 代表第一个参数 type para844 struct { s string t string } // ans 是答案 // one 代表第一个答案 type ans844 struct { one bool } func Test_Problem844(t *testing.T) { qs := []question844{ { para844{"ab#c", "ad#c"}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0844.Backspace-String-Compare/844. Backspace String Compare.go
leetcode/0844.Backspace-String-Compare/844. Backspace String Compare.go
package leetcode func backspaceCompare(S string, T string) bool { s := make([]rune, 0) for _, c := range S { if c == '#' { if len(s) > 0 { s = s[:len(s)-1] } } else { s = append(s, c) } } s2 := make([]rune, 0) for _, c := range T { if c == '#' { if len(s2) > 0 { s2 = s2[:len(s2)-1] ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0454.4Sum-II/454. 4Sum II_test.go
leetcode/0454.4Sum-II/454. 4Sum II_test.go
package leetcode import ( "fmt" "testing" ) type question454 struct { para454 ans454 } // para 是参数 // one 代表第一个参数 type para454 struct { a []int b []int c []int d []int } // ans 是答案 // one 代表第一个答案 type ans454 struct { one int } func Test_Problem454(t *testing.T) { qs := []question454{ { para454{[]i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0454.4Sum-II/454. 4Sum II.go
leetcode/0454.4Sum-II/454. 4Sum II.go
package leetcode func fourSumCount(A []int, B []int, C []int, D []int) int { m := make(map[int]int, len(A)*len(B)) for _, a := range A { for _, b := range B { m[a+b]++ } } ret := 0 for _, c := range C { for _, d := range D { ret += m[0-c-d] } } return ret }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0150.Evaluate-Reverse-Polish-Notation/150. Evaluate Reverse Polish Notation.go
leetcode/0150.Evaluate-Reverse-Polish-Notation/150. Evaluate Reverse Polish Notation.go
package leetcode import ( "strconv" ) func evalRPN(tokens []string) int { stack := make([]int, 0, len(tokens)) for _, token := range tokens { v, err := strconv.Atoi(token) if err == nil { stack = append(stack, v) } else { num1, num2 := stack[len(stack)-2], stack[len(stack)-1] stack = stack[:len(stac...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0150.Evaluate-Reverse-Polish-Notation/150. Evaluate Reverse Polish Notation_test.go
leetcode/0150.Evaluate-Reverse-Polish-Notation/150. Evaluate Reverse Polish Notation_test.go
package leetcode import ( "fmt" "testing" ) type question150 struct { para150 ans150 } // para 是参数 // one 代表第一个参数 type para150 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans150 struct { one int } func Test_Problem150(t *testing.T) { qs := []question150{ { para150{[]string{"18"}}, ans15...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0729.My-Calendar-I/729. My Calendar I.go
leetcode/0729.My-Calendar-I/729. My Calendar I.go
package leetcode // 解法一 二叉排序树 // Event define type Event struct { start, end int left, right *Event } // Insert define func (e *Event) Insert(curr *Event) bool { if e.end > curr.start && curr.end > e.start { return false } if curr.start < e.start { if e.left == nil { e.left = curr } else { return e....
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0729.My-Calendar-I/729. My Calendar I_test.go
leetcode/0729.My-Calendar-I/729. My Calendar I_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem729(t *testing.T) { obj := Constructor729() param1 := obj.Book(10, 20) fmt.Printf("param = %v obj = %v\n", param1, obj) param1 = obj.Book(15, 25) fmt.Printf("param = %v obj = %v\n", param1, obj) param1 = obj.Book(20, 30) fmt.Printf("param = %v obj ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0051.N-Queens/51. N-Queens.go
leetcode/0051.N-Queens/51. N-Queens.go
package leetcode // 解法一 DFS func solveNQueens(n int) [][]string { col, dia1, dia2, row, res := make([]bool, n), make([]bool, 2*n-1), make([]bool, 2*n-1), []int{}, [][]string{} putQueen(n, 0, &col, &dia1, &dia2, &row, &res) return res } // 尝试在一个n皇后问题中, 摆放第index行的皇后位置 func putQueen(n, index int, col, dia1, dia2 *[]b...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0051.N-Queens/51. N-Queens_test.go
leetcode/0051.N-Queens/51. N-Queens_test.go
package leetcode import ( "fmt" "testing" ) type question51 struct { para51 ans51 } // para 是参数 // one 代表第一个参数 type para51 struct { one int } // ans 是答案 // one 代表第一个答案 type ans51 struct { one [][]string } func Test_Problem51(t *testing.T) { qs := []question51{ { para51{4}, ans51{[][]string{ {"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0050.Powx-n/50. Pow(x, n).go
leetcode/0050.Powx-n/50. Pow(x, n).go
package leetcode // 时间复杂度 O(log n),空间复杂度 O(1) func myPow(x float64, n int) float64 { if n == 0 { return 1 } if n == 1 { return x } if n < 0 { n = -n x = 1 / x } tmp := myPow(x, n/2) if n%2 == 0 { return tmp * tmp } return tmp * tmp * x }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0050.Powx-n/50. Pow(x, n)_test.go
leetcode/0050.Powx-n/50. Pow(x, n)_test.go
package leetcode import ( "fmt" "testing" ) type question50 struct { para50 ans50 } // para 是参数 // one 代表第一个参数 type para50 struct { x float64 n int } // ans 是答案 // one 代表第一个答案 type ans50 struct { one float64 } func Test_Problem50(t *testing.T) { qs := []question50{ { para50{2.00000, 10}, ans50{10...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1758.Minimum-Changes-To-Make-Alternating-Binary-String/1758. Minimum Changes To Make Alternating Binary String.go
leetcode/1758.Minimum-Changes-To-Make-Alternating-Binary-String/1758. Minimum Changes To Make Alternating Binary String.go
package leetcode func minOperations(s string) int { res := 0 for i := 0; i < len(s); i++ { if int(s[i]-'0') != i%2 { res++ } } return min(res, len(s)-res) } func min(a, b int) int { if a > b { return b } return a }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1758.Minimum-Changes-To-Make-Alternating-Binary-String/1758. Minimum Changes To Make Alternating Binary String_test.go
leetcode/1758.Minimum-Changes-To-Make-Alternating-Binary-String/1758. Minimum Changes To Make Alternating Binary String_test.go
package leetcode import ( "fmt" "testing" ) type question1758 struct { para1758 ans1758 } // para 是参数 // one 代表第一个参数 type para1758 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1758 struct { one int } func Test_Problem1758(t *testing.T) { qs := []question1758{ { para1758{"0100"}, ans1758{1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary.go
leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary.go
package leetcode func minMoves(nums []int, limit int) int { diff := make([]int, limit*2+2) // nums[i] <= limit, b+limit+1 is maximum limit+limit+1 for j := 0; j < len(nums)/2; j++ { a, b := min(nums[j], nums[len(nums)-j-1]), max(nums[j], nums[len(nums)-j-1]) // using prefix sum: most interesting point, and is th...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary_test.go
leetcode/1674.Minimum-Moves-to-Make-Array-Complementary/1674. Minimum Moves to Make Array Complementary_test.go
package leetcode import ( "fmt" "testing" ) type question1674 struct { para1674 ans1674 } // para 是参数 // one 代表第一个参数 type para1674 struct { nums []int limit int } // ans 是答案 // one 代表第一个答案 type ans1674 struct { one int } func Test_Problem1674(t *testing.T) { qs := []question1674{ { para1674{[]int{1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0107.Binary-Tree-Level-Order-Traversal-II/107. Binary Tree Level Order Traversal II_test.go
leetcode/0107.Binary-Tree-Level-Order-Traversal-II/107. Binary Tree Level Order Traversal II_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question107 struct { para107 ans107 } // para 是参数 // one 代表第一个参数 type para107 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans107 struct { one [][]int } func Test_Problem107(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/0107.Binary-Tree-Level-Order-Traversal-II/107. Binary Tree Level Order Traversal II.go
leetcode/0107.Binary-Tree-Level-Order-Traversal-II/107. Binary Tree Level Order Traversal II.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func levelOrderBottom(root *TreeNode) [][]int { t...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1020.Number-of-Enclaves/1020. Number of Enclaves.go
leetcode/1020.Number-of-Enclaves/1020. Number of Enclaves.go
package leetcode var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } func numEnclaves(A [][]int) int { m, n := len(A), len(A[0]) for i := 0; i < m; i++ { for j := 0; j < n; j++ { if i == 0 || i == m-1 || j == 0 || j == n-1 { if A[i][j] == 1 { dfsNumEnclaves(A, i, j) } } } } count := ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1020.Number-of-Enclaves/1020. Number of Enclaves_test.go
leetcode/1020.Number-of-Enclaves/1020. Number of Enclaves_test.go
package leetcode import ( "fmt" "testing" ) type question1020 struct { para1020 ans1020 } // para 是参数 // one 代表第一个参数 type para1020 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans1020 struct { one int } func Test_Problem1020(t *testing.T) { qs := []question1020{ { para1020{[][]int{ {1, 1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2171.Removing-Minimum-Number-of-Magic-Beans/2171. Removing Minimum Number of Magic Beans.go
leetcode/2171.Removing-Minimum-Number-of-Magic-Beans/2171. Removing Minimum Number of Magic Beans.go
package leetcode import "sort" func minimumRemoval(beans []int) int64 { sort.Ints(beans) sum, mx := 0, 0 for i, v := range beans { sum += v mx = max(mx, (len(beans)-i)*v) } return int64(sum - mx) } func max(a, b int) int { if b > a { return b } return a }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2171.Removing-Minimum-Number-of-Magic-Beans/2171. Removing Minimum Number of Magic Beans_test.go
leetcode/2171.Removing-Minimum-Number-of-Magic-Beans/2171. Removing Minimum Number of Magic Beans_test.go
package leetcode import ( "fmt" "testing" ) type question2170 struct { para2170 ans2170 } // para 是参数 // one 代表第一个参数 type para2170 struct { beans []int } // ans 是答案 // one 代表第一个答案 type ans2170 struct { one int } func Test_Problem1(t *testing.T) { qs := []question2170{ { para2170{[]int{4, 1, 6, 5}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0993.Cousins-in-Binary-Tree/993. Cousins in Binary Tree_test.go
leetcode/0993.Cousins-in-Binary-Tree/993. Cousins in Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question993 struct { para993 ans993 } // para 是参数 // one 代表第一个参数 type para993 struct { one []int x int y int } // ans 是答案 // one 代表第一个答案 type ans993 struct { one bool } func Test_Problem993(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/0993.Cousins-in-Binary-Tree/993. Cousins in Binary Tree.go
leetcode/0993.Cousins-in-Binary-Tree/993. Cousins in Binary Tree.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ // 解法一 递归 func isCousins(root *TreeNode, x int, y ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0457.Circular-Array-Loop/457. Circular Array Loop.go
leetcode/0457.Circular-Array-Loop/457. Circular Array Loop.go
package leetcode func circularArrayLoop(nums []int) bool { if len(nums) == 0 { return false } for i := 0; i < len(nums); i++ { if nums[i] == 0 { continue } // slow/fast pointer slow, fast, val := i, getNextIndex(nums, i), 0 for nums[fast]*nums[i] > 0 && nums[getNextIndex(nums, fast)]*nums[i] > 0 { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0457.Circular-Array-Loop/457. Circular Array Loop_test.go
leetcode/0457.Circular-Array-Loop/457. Circular Array Loop_test.go
package leetcode import ( "fmt" "testing" ) type question457 struct { para457 ans457 } // para 是参数 // one 代表第一个参数 type para457 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans457 struct { one bool } func Test_Problem457(t *testing.T) { qs := []question457{ { para457{[]int{-1}}, ans457{false...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0622.Design-Circular-Queue/622. Design Circular Queue_test.go
leetcode/0622.Design-Circular-Queue/622. Design Circular Queue_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem622(t *testing.T) { obj := Constructor(3) fmt.Printf("obj = %v\n", obj) param1 := obj.EnQueue(1) fmt.Printf("param_1 = %v obj = %v\n", param1, obj) param2 := obj.DeQueue() fmt.Printf("param_1 = %v obj = %v\n", param2, obj) param3 := obj.Front() fm...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0622.Design-Circular-Queue/622. Design Circular Queue.go
leetcode/0622.Design-Circular-Queue/622. Design Circular Queue.go
package leetcode type MyCircularQueue struct { cap int size int queue []int left int right int } func Constructor(k int) MyCircularQueue { return MyCircularQueue{cap: k, size: 0, left: 0, right: 0, queue: make([]int, k)} } func (this *MyCircularQueue) EnQueue(value int) bool { if this.size == this.cap { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0391.Perfect-Rectangle/391.Perfect Rectangle.go
leetcode/0391.Perfect-Rectangle/391.Perfect Rectangle.go
package leetcode type point struct { x int y int } func isRectangleCover(rectangles [][]int) bool { minX, minY, maxA, maxB := rectangles[0][0], rectangles[0][1], rectangles[0][2], rectangles[0][3] area := 0 cnt := make(map[point]int) for _, v := range rectangles { x, y, a, b := v[0], v[1], v[2], v[3] area +...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0391.Perfect-Rectangle/391.Perfect Rectangle_test.go
leetcode/0391.Perfect-Rectangle/391.Perfect Rectangle_test.go
package leetcode import ( "fmt" "testing" ) type question391 struct { para391 ans391 } // para 是参数 type para391 struct { rectangles [][]int } // ans 是答案 type ans391 struct { ans bool } func Test_Problem391(t *testing.T) { qs := []question391{ { para391{[][]int{{1, 1, 3, 3}, {3, 1, 4, 2}, {3, 2, 4, 4}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0002.Add-Two-Numbers/2. Add Two Numbers_test.go
leetcode/0002.Add-Two-Numbers/2. Add Two Numbers_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question2 struct { para2 ans2 } // para 是参数 // one 代表第一个参数 type para2 struct { one []int another []int } // ans 是答案 // one 代表第一个答案 type ans2 struct { one []int } func Test_Problem2(t *testing.T) { qs := []q...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0002.Add-Two-Numbers/2. Add Two Numbers.go
leetcode/0002.Add-Two-Numbers/2. Add Two Numbers.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 addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode { head := &List...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1636.Sort-Array-by-Increasing-Frequency/1636. Sort Array by Increasing Frequency_test.go
leetcode/1636.Sort-Array-by-Increasing-Frequency/1636. Sort Array by Increasing Frequency_test.go
package leetcode import ( "fmt" "testing" ) type question1636 struct { para1636 ans1636 } // para 是参数 // one 代表第一个参数 type para1636 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1636 struct { one []int } func Test_Problem1636(t *testing.T) { qs := []question1636{ { para1636{[]int{1, 1, 2, 2,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1636.Sort-Array-by-Increasing-Frequency/1636. Sort Array by Increasing Frequency.go
leetcode/1636.Sort-Array-by-Increasing-Frequency/1636. Sort Array by Increasing Frequency.go
package leetcode import "sort" func frequencySort(nums []int) []int { freq := map[int]int{} for _, v := range nums { freq[v]++ } sort.Slice(nums, func(i, j int) bool { if freq[nums[i]] == freq[nums[j]] { return nums[j] < nums[i] } return freq[nums[i]] < freq[nums[j]] }) return nums }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream.go
leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream.go
package leetcode type OrderedStream struct { ptr int stream []string } func Constructor(n int) OrderedStream { ptr, stream := 1, make([]string, n+1) return OrderedStream{ptr: ptr, stream: stream} } func (this *OrderedStream) Insert(id int, value string) []string { this.stream[id] = value res := []string{} ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream_test.go
leetcode/1656.Design-an-Ordered-Stream/1656. Design an Ordered Stream_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem1656(t *testing.T) { obj := Constructor(5) fmt.Printf("obj = %v\n", obj) param1 := obj.Insert(3, "ccccc") fmt.Printf("param_1 = %v obj = %v\n", param1, obj) param1 = obj.Insert(1, "aaaaa") fmt.Printf("param_1 = %v obj = %v\n", param1, obj) param1 =...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0304.Range-Sum-Query-2D-Immutable/304. Range Sum Query 2D - Immutable_test.go
leetcode/0304.Range-Sum-Query-2D-Immutable/304. Range Sum Query 2D - Immutable_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem304(t *testing.T) { obj := Constructor( [][]int{ {3, 0, 1, 4, 2}, {5, 6, 3, 2, 1}, {1, 2, 0, 1, 5}, {4, 1, 0, 1, 7}, {1, 0, 3, 0, 5}, }, ) fmt.Printf("obj = %v\n", obj.SumRegion(2, 1, 4, 3)) fmt.Printf("obj = %v\n", obj.SumRegion(1,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0304.Range-Sum-Query-2D-Immutable/304. Range Sum Query 2D - Immutable.go
leetcode/0304.Range-Sum-Query-2D-Immutable/304. Range Sum Query 2D - Immutable.go
package leetcode type NumMatrix struct { cumsum [][]int } func Constructor(matrix [][]int) NumMatrix { if len(matrix) == 0 { return NumMatrix{nil} } cumsum := make([][]int, len(matrix)+1) cumsum[0] = make([]int, len(matrix[0])+1) for i := range matrix { cumsum[i+1] = make([]int, len(matrix[i])+1) for j :=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0097.Interleaving-String/97. Interleaving String.go
leetcode/0097.Interleaving-String/97. Interleaving String.go
package leetcode func isInterleave(s1 string, s2 string, s3 string) bool { if len(s1)+len(s2) != len(s3) { return false } visited := make(map[int]bool) return dfs(s1, s2, s3, 0, 0, visited) } func dfs(s1, s2, s3 string, p1, p2 int, visited map[int]bool) bool { if p1+p2 == len(s3) { return true } if _, ok :...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0097.Interleaving-String/97. Interleaving String_test.go
leetcode/0097.Interleaving-String/97. Interleaving String_test.go
package leetcode import ( "fmt" "testing" ) type question97 struct { para97 ans97 } // para 是参数 // one 代表第一个参数 type para97 struct { s1 string s2 string s3 string } // ans 是答案 // one 代表第一个答案 type ans97 struct { one bool } func Test_Problem97(t *testing.T) { qs := []question97{ { para97{"aabcc", "dbb...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1154.Day-of-the-Year/1154. Day of the Year.go
leetcode/1154.Day-of-the-Year/1154. Day of the Year.go
package leetcode import "time" func dayOfYear(date string) int { first := date[:4] + "-01-01" firstDay, _ := time.Parse("2006-01-02", first) dateDay, _ := time.Parse("2006-01-02", date) duration := dateDay.Sub(firstDay) return int(duration.Hours())/24 + 1 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1154.Day-of-the-Year/1154. Day of the Year_test.go
leetcode/1154.Day-of-the-Year/1154. Day of the Year_test.go
package leetcode import ( "fmt" "testing" ) type question1154 struct { para1154 ans1154 } // para 是参数 // one 代表第一个参数 type para1154 struct { one string } // ans 是答案 // one 代表第一个答案 type ans1154 struct { one int } func Test_Problem1154(t *testing.T) { qs := []question1154{ { para1154{"2019-01-09"}, a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0100.Same-Tree/100. Same Tree.go
leetcode/0100.Same-Tree/100. Same 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 isSameTree(p *TreeNode, q *TreeNode) bool { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0100.Same-Tree/100. Same Tree_test.go
leetcode/0100.Same-Tree/100. Same Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question100 struct { para100 ans100 } // para 是参数 // one 代表第一个参数 type para100 struct { one []int two []int } // ans 是答案 // one 代表第一个答案 type ans100 struct { one bool } func Test_Problem100(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/0661.Image-Smoother/661. Image Smoother.go
leetcode/0661.Image-Smoother/661. Image Smoother.go
package leetcode func imageSmoother(M [][]int) [][]int { res := make([][]int, len(M)) for i := range M { res[i] = make([]int, len(M[0])) } for y := 0; y < len(M); y++ { for x := 0; x < len(M[0]); x++ { res[y][x] = smooth(x, y, M) } } return res } func smooth(x, y int, M [][]int) int { count, sum := 1,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0661.Image-Smoother/661. Image Smoother_test.go
leetcode/0661.Image-Smoother/661. Image Smoother_test.go
package leetcode import ( "fmt" "testing" ) type question661 struct { para661 ans661 } // para 是参数 // one 代表第一个参数 type para661 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans661 struct { one [][]int } func Test_Problem661(t *testing.T) { qs := []question661{ { para661{[][]int{{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/1319.Number-of-Operations-to-Make-Network-Connected/1319. Number of Operations to Make Network Connected_test.go
leetcode/1319.Number-of-Operations-to-Make-Network-Connected/1319. Number of Operations to Make Network Connected_test.go
package leetcode import ( "fmt" "testing" ) type question1319 struct { para1319 ans1319 } // para 是参数 // one 代表第一个参数 type para1319 struct { n int connections [][]int } // ans 是答案 // one 代表第一个答案 type ans1319 struct { one int } func Test_Problem1319(t *testing.T) { qs := []question1319{ { pa...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1319.Number-of-Operations-to-Make-Network-Connected/1319. Number of Operations to Make Network Connected.go
leetcode/1319.Number-of-Operations-to-Make-Network-Connected/1319. Number of Operations to Make Network Connected.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) func makeConnected(n int, connections [][]int) int { if n-1 > len(connections) { return -1 } uf, redundance := template.UnionFind{}, 0 uf.Init(n) for _, connection := range connections { if uf.Find(connection[0]) == uf.Find(connection[1]...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false