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/0337.House-Robber-III/337. House Robber III_test.go
leetcode/0337.House-Robber-III/337. House Robber III_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question337 struct { para337 ans337 } // para 是参数 // one 代表第一个参数 type para337 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans337 struct { one int } func Test_Problem337(t *testing.T) { qs := []question33...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0337.House-Robber-III/337. House Robber III.go
leetcode/0337.House-Robber-III/337. House Robber III.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 rob337(root *TreeNode) int { a, b := dfsTreeR...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0179.Largest-Number/179. Largest Number.go
leetcode/0179.Largest-Number/179. Largest Number.go
package leetcode import ( "strconv" ) func largestNumber(nums []int) string { if len(nums) == 0 { return "" } numStrs := toStringArray(nums) quickSortString(numStrs, 0, len(numStrs)-1) res := "" for _, str := range numStrs { if res == "0" && str == "0" { continue } res = res + str } return res } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0179.Largest-Number/179. Largest Number_test.go
leetcode/0179.Largest-Number/179. Largest Number_test.go
package leetcode import ( "fmt" "testing" ) type question179 struct { para179 ans179 } // para 是参数 // one 代表第一个参数 type para179 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans179 struct { one string } func Test_Problem179(t *testing.T) { qs := []question179{ { para179{[]int{3, 6, 9, 1}}, an...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0042.Trapping-Rain-Water/42. Trapping Rain Water.go
leetcode/0042.Trapping-Rain-Water/42. Trapping Rain Water.go
package leetcode func trap(height []int) int { res, left, right, maxLeft, maxRight := 0, 0, len(height)-1, 0, 0 for left <= right { if height[left] <= height[right] { if height[left] > maxLeft { maxLeft = height[left] } else { res += maxLeft - height[left] } left++ } else { if height[right...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0042.Trapping-Rain-Water/42. Trapping Rain Water_test.go
leetcode/0042.Trapping-Rain-Water/42. Trapping Rain Water_test.go
package leetcode import ( "fmt" "testing" ) type question42 struct { para42 ans42 } // para 是参数 // one 代表第一个参数 type para42 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans42 struct { one int } func Test_Problem42(t *testing.T) { qs := []question42{ { para42{[]int{0, 1, 0, 2, 1, 0, 1, 3, 2, 1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0881.Boats-to-Save-People/881. Boats to Save People.go
leetcode/0881.Boats-to-Save-People/881. Boats to Save People.go
package leetcode import ( "sort" ) func numRescueBoats(people []int, limit int) int { sort.Ints(people) left, right, res := 0, len(people)-1, 0 for left <= right { if left == right { res++ return res } if people[left]+people[right] <= limit { left++ right-- } else { right-- } res++ } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0881.Boats-to-Save-People/881. Boats to Save People_test.go
leetcode/0881.Boats-to-Save-People/881. Boats to Save People_test.go
package leetcode import ( "fmt" "testing" ) type question881 struct { para881 ans881 } // para 是参数 // one 代表第一个参数 type para881 struct { s []int k int } // ans 是答案 // one 代表第一个答案 type ans881 struct { one int } func Test_Problem881(t *testing.T) { qs := []question881{ { para881{[]int{1, 2}, 3}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0803.Bricks-Falling-When-Hit/803. Bricks Falling When Hit_test.go
leetcode/0803.Bricks-Falling-When-Hit/803. Bricks Falling When Hit_test.go
package leetcode import ( "fmt" "testing" ) type question803 struct { para803 ans803 } // para 是参数 // one 代表第一个参数 type para803 struct { grid [][]int hits [][]int } // ans 是答案 // one 代表第一个答案 type ans803 struct { one []int } func Test_Problem803(t *testing.T) { qs := []question803{ { para803{[][]int{{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0803.Bricks-Falling-When-Hit/803. Bricks Falling When Hit.go
leetcode/0803.Bricks-Falling-When-Hit/803. Bricks Falling When Hit.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/template" ) var dir = [][]int{ {-1, 0}, {0, 1}, {1, 0}, {0, -1}, } func hitBricks(grid [][]int, hits [][]int) []int { if len(hits) == 0 { return []int{} } uf, m, n, res, oriCount := template.UnionFindCount{}, len(grid), len(grid[0]), make([]int, le...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0405.Convert-a-Number-to-Hexadecimal/405. Convert a Number to Hexadecimal_test.go
leetcode/0405.Convert-a-Number-to-Hexadecimal/405. Convert a Number to Hexadecimal_test.go
package leetcode import ( "fmt" "testing" ) type question405 struct { para405 ans405 } // para 是参数 // one 代表第一个参数 type para405 struct { one int } // ans 是答案 // one 代表第一个答案 type ans405 struct { one string } func Test_Problem405(t *testing.T) { qs := []question405{ { para405{26}, ans405{"1a"}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0405.Convert-a-Number-to-Hexadecimal/405. Convert a Number to Hexadecimal.go
leetcode/0405.Convert-a-Number-to-Hexadecimal/405. Convert a Number to Hexadecimal.go
package leetcode func toHex(num int) string { if num == 0 { return "0" } if num < 0 { num += 1 << 32 } mp := map[int]string{ 0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10: "a", 11: "b", 12: "c", 13: "d", 14: "e", 15: "f", } var bitArr []string for num > 0 { bitArr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0846.Hand-of-Straights/846.Hand of Straights_test.go
leetcode/0846.Hand-of-Straights/846.Hand of Straights_test.go
package leetcode import ( "fmt" "testing" ) type question846 struct { para846 ans846 } // para 是参数 type para846 struct { hand []int groupSize int } // ans 是答案 type ans846 struct { ans bool } func Test_Problem846(t *testing.T) { qs := []question846{ { para846{[]int{1, 2, 3, 6, 2, 3, 4, 7, 8}, 3}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0846.Hand-of-Straights/846.Hand of Straights.go
leetcode/0846.Hand-of-Straights/846.Hand of Straights.go
package leetcode import "sort" func isNStraightHand(hand []int, groupSize int) bool { mp := make(map[int]int) for _, v := range hand { mp[v] += 1 } sort.Ints(hand) for _, num := range hand { if mp[num] == 0 { continue } for diff := 0; diff < groupSize; diff++ { if mp[num+diff] == 0 { return fal...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0971.Flip-Binary-Tree-To-Match-Preorder-Traversal/971. Flip Binary Tree To Match Preorder Traversal.go
leetcode/0971.Flip-Binary-Tree-To-Match-Preorder-Traversal/971. Flip Binary Tree To Match Preorder Traversal.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func flipMatchVoyage(root *TreeNode, voyage []int)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0971.Flip-Binary-Tree-To-Match-Preorder-Traversal/971. Flip Binary Tree To Match Preorder Traversal_test.go
leetcode/0971.Flip-Binary-Tree-To-Match-Preorder-Traversal/971. Flip Binary Tree To Match Preorder Traversal_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question971 struct { para971 ans971 } // para 是参数 // one 代表第一个参数 type para971 struct { one []int voyage []int } // ans 是答案 // one 代表第一个答案 type ans971 struct { one []int } func Test_Problem971(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/0532.K-diff-Pairs-in-an-Array/532. K-diff Pairs in an Array.go
leetcode/0532.K-diff-Pairs-in-an-Array/532. K-diff Pairs in an Array.go
package leetcode func findPairs(nums []int, k int) int { if k < 0 || len(nums) == 0 { return 0 } var count int m := make(map[int]int, len(nums)) for _, value := range nums { m[value]++ } for key := range m { if k == 0 && m[key] > 1 { count++ continue } if k > 0 && m[key+k] > 0 { count++ } ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0532.K-diff-Pairs-in-an-Array/532. K-diff Pairs in an Array_test.go
leetcode/0532.K-diff-Pairs-in-an-Array/532. K-diff Pairs in an Array_test.go
package leetcode import ( "fmt" "testing" ) type question532 struct { para532 ans532 } // para 是参数 // one 代表第一个参数 type para532 struct { one []int n int } // ans 是答案 // one 代表第一个答案 type ans532 struct { one int } func Test_Problem532(t *testing.T) { qs := []question532{ { para532{[]int{3, 1, 4, 1, 5...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1437.Check-If-All-1s-Are-at-Least-Length-K-Places-Away/1437. Check If All 1s Are at Least Length K Places Away.go
leetcode/1437.Check-If-All-1s-Are-at-Least-Length-K-Places-Away/1437. Check If All 1s Are at Least Length K Places Away.go
package leetcode func kLengthApart(nums []int, k int) bool { prevIndex := -1 for i, num := range nums { if num == 1 { if prevIndex != -1 && i-prevIndex-1 < k { return false } prevIndex = i } } return true }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1437.Check-If-All-1s-Are-at-Least-Length-K-Places-Away/1437. Check If All 1s Are at Least Length K Places Away_test.go
leetcode/1437.Check-If-All-1s-Are-at-Least-Length-K-Places-Away/1437. Check If All 1s Are at Least Length K Places Away_test.go
package leetcode import ( "fmt" "testing" ) type question1437 struct { para1437 ans1437 } // para 是参数 // one 代表第一个参数 type para1437 struct { nums []int k int } // ans 是答案 // one 代表第一个答案 type ans1437 struct { one bool } func Test_Problem1437(t *testing.T) { qs := []question1437{ { para1437{[]int{1,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1732.Find-the-Highest-Altitude/1732. Find the Highest Altitude.go
leetcode/1732.Find-the-Highest-Altitude/1732. Find the Highest Altitude.go
package leetcode func largestAltitude(gain []int) int { max, height := 0, 0 for _, g := range gain { height += g if height > max { max = height } } return max }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1732.Find-the-Highest-Altitude/1732. Find the Highest Altitude_test.go
leetcode/1732.Find-the-Highest-Altitude/1732. Find the Highest Altitude_test.go
package leetcode import ( "fmt" "testing" ) type question1732 struct { para1732 ans1732 } // para 是参数 // one 代表第一个参数 type para1732 struct { gain []int } // ans 是答案 // one 代表第一个答案 type ans1732 struct { one int } func Test_Problem1732(t *testing.T) { qs := []question1732{ { para1732{[]int{-5, 1, 5, 0, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0207.Course-Schedule/207. Course Schedule.go
leetcode/0207.Course-Schedule/207. Course Schedule.go
package leetcode // AOV 网的拓扑排序 func canFinish(n int, pre [][]int) bool { in := make([]int, n) frees := make([][]int, n) next := make([]int, 0, n) for _, v := range pre { in[v[0]]++ frees[v[1]] = append(frees[v[1]], v[0]) } for i := 0; i < n; i++ { if in[i] == 0 { next = append(next, i) } } for i := ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0207.Course-Schedule/207. Course Schedule_test.go
leetcode/0207.Course-Schedule/207. Course Schedule_test.go
package leetcode import ( "fmt" "testing" ) type question207 struct { para207 ans207 } // para 是参数 // one 代表第一个参数 type para207 struct { one int pre [][]int } // ans 是答案 // one 代表第一个答案 type ans207 struct { one bool } func Test_Problem207(t *testing.T) { qs := []question207{ { para207{2, [][]int{{1, 0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0986.Interval-List-Intersections/986. Interval List Intersections.go
leetcode/0986.Interval-List-Intersections/986. Interval List Intersections.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // Interval define type Interval = structures.Interval /** * Definition for an interval. * type Interval struct { * Start int * End int * } */ func intervalIntersection(A []Interval, B []Interval) []Interval { res := []Interval{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0986.Interval-List-Intersections/986. Interval List Intersections_test.go
leetcode/0986.Interval-List-Intersections/986. Interval List Intersections_test.go
package leetcode import ( "fmt" "testing" ) type question986 struct { para986 ans986 } // para 是参数 // one 代表第一个参数 type para986 struct { one []Interval two []Interval } // ans 是答案 // one 代表第一个答案 type ans986 struct { one []Interval } func Test_Problem986(t *testing.T) { qs := []question986{ { para986{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0091.Decode-Ways/91. Decode Ways_test.go
leetcode/0091.Decode-Ways/91. Decode Ways_test.go
package leetcode import ( "fmt" "testing" ) type question91 struct { para91 ans91 } // para 是参数 // one 代表第一个参数 type para91 struct { one string } // ans 是答案 // one 代表第一个答案 type ans91 struct { one int } func Test_Problem91(t *testing.T) { qs := []question91{ { para91{"12"}, ans91{2}, }, { pa...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0091.Decode-Ways/91. Decode Ways.go
leetcode/0091.Decode-Ways/91. Decode Ways.go
package leetcode func numDecodings(s string) int { n := len(s) dp := make([]int, n+1) dp[0] = 1 for i := 1; i <= n; i++ { if s[i-1] != '0' { dp[i] += dp[i-1] } if i > 1 && s[i-2] != '0' && (s[i-2]-'0')*10+(s[i-1]-'0') <= 26 { dp[i] += dp[i-2] } } return dp[n] }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1337.The-K-Weakest-Rows-in-a-Matrix/1337. The K Weakest Rows in a Matrix.go
leetcode/1337.The-K-Weakest-Rows-in-a-Matrix/1337. The K Weakest Rows in a Matrix.go
package leetcode func kWeakestRows(mat [][]int, k int) []int { res := []int{} for j := 0; j < len(mat[0]); j++ { for i := 0; i < len(mat); i++ { if mat[i][j] == 0 && ((j == 0) || (mat[i][j-1] != 0)) { res = append(res, i) } } } for i := 0; i < len(mat); i++ { if mat[i][len(mat[0])-1] == 1 { res ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1337.The-K-Weakest-Rows-in-a-Matrix/1337. The K Weakest Rows in a Matrix_test.go
leetcode/1337.The-K-Weakest-Rows-in-a-Matrix/1337. The K Weakest Rows in a Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question1337 struct { para1337 ans1337 } // para 是参数 // one 代表第一个参数 type para1337 struct { mat [][]int k int } // ans 是答案 // one 代表第一个答案 type ans1337 struct { one []int } func Test_Problem1337(t *testing.T) { qs := []question1337{ { para1337{[][]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0297.Serialize-and-Deserialize-Binary-Tree/297.Serialize and Deserialize Binary Tree_test.go
leetcode/0297.Serialize-and-Deserialize-Binary-Tree/297.Serialize and Deserialize Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question297 struct { para297 ans297 } // para 是参数 // one 代表第一个参数 type para297 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans297 struct { one []int } func Test_Problem297(t *testing.T) { qs := []question2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0297.Serialize-and-Deserialize-Binary-Tree/297.Serialize and Deserialize Binary Tree.go
leetcode/0297.Serialize-and-Deserialize-Binary-Tree/297.Serialize and Deserialize Binary Tree.go
package leetcode import ( "strconv" "strings" "github.com/halfrost/LeetCode-Go/structures" ) type TreeNode = structures.TreeNode type Codec struct { builder strings.Builder input []string } func Constructor() Codec { return Codec{} } // Serializes a tree to a single string. func (this *Codec) serialize(ro...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0268.Missing-Number/268. Missing Number_test.go
leetcode/0268.Missing-Number/268. Missing Number_test.go
package leetcode import ( "fmt" "testing" ) type question268 struct { para268 ans268 } // para 是参数 // one 代表第一个参数 type para268 struct { s []int } // ans 是答案 // one 代表第一个答案 type ans268 struct { one int } func Test_Problem268(t *testing.T) { qs := []question268{ { para268{[]int{3, 0, 1}}, ans268{2},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0268.Missing-Number/268. Missing Number.go
leetcode/0268.Missing-Number/268. Missing Number.go
package leetcode func missingNumber(nums []int) int { xor, i := 0, 0 for i = 0; i < len(nums); i++ { xor = xor ^ i ^ nums[i] } return xor ^ i }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1576.Replace-All-s-to-Avoid-Consecutive-Repeating-Characters/1576. Replace-All-s-to-Avoid-Consecutive-Repeating-Characters.go
leetcode/1576.Replace-All-s-to-Avoid-Consecutive-Repeating-Characters/1576. Replace-All-s-to-Avoid-Consecutive-Repeating-Characters.go
package leetcode func modifyString(s string) string { res := []byte(s) for i, ch := range res { if ch == '?' { for b := byte('a'); b <= 'z'; b++ { if !(i > 0 && res[i-1] == b || i < len(res)-1 && res[i+1] == b) { res[i] = b break } } } } return string(res) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1576.Replace-All-s-to-Avoid-Consecutive-Repeating-Characters/1576. Replace-All-s-to-Avoid-Consecutive-Repeating-Characters_test.go
leetcode/1576.Replace-All-s-to-Avoid-Consecutive-Repeating-Characters/1576. Replace-All-s-to-Avoid-Consecutive-Repeating-Characters_test.go
package leetcode import ( "fmt" "testing" ) type question1576 struct { para1576 ans1576 } // para 是参数 // one 代表第一个参数 type para1576 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1576 struct { one string } func Test_Problem1576(t *testing.T) { qs := []question1576{ { para1576{"?zs"}, ans1576...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0735.Asteroid-Collision/735. Asteroid Collision_test.go
leetcode/0735.Asteroid-Collision/735. Asteroid Collision_test.go
package leetcode import ( "fmt" "testing" ) type question735 struct { para735 ans735 } // para 是参数 // one 代表第一个参数 type para735 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans735 struct { one []int } func Test_Problem735(t *testing.T) { qs := []question735{ { para735{[]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/0735.Asteroid-Collision/735. Asteroid Collision.go
leetcode/0735.Asteroid-Collision/735. Asteroid Collision.go
package leetcode func asteroidCollision(asteroids []int) []int { res := []int{} for _, v := range asteroids { for len(res) != 0 && res[len(res)-1] > 0 && res[len(res)-1] < -v { res = res[:len(res)-1] } if len(res) == 0 || v > 0 || res[len(res)-1] < 0 { res = append(res, v) } else if v < 0 && res[len(re...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1385.Find-the-Distance-Value-Between-Two-Arrays/1385. Find the Distance Value Between Two Arrays.go
leetcode/1385.Find-the-Distance-Value-Between-Two-Arrays/1385. Find the Distance Value Between Two Arrays.go
package leetcode func findTheDistanceValue(arr1 []int, arr2 []int, d int) int { res := 0 for i := range arr1 { for j := range arr2 { if abs(arr1[i]-arr2[j]) <= d { break } if j == len(arr2)-1 { res++ } } } return res } func abs(a int) int { if a < 0 { return -1 * a } return a }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1385.Find-the-Distance-Value-Between-Two-Arrays/1385. Find the Distance Value Between Two Arrays_test.go
leetcode/1385.Find-the-Distance-Value-Between-Two-Arrays/1385. Find the Distance Value Between Two Arrays_test.go
package leetcode import ( "fmt" "testing" ) type question1385 struct { para1385 ans1385 } // para 是参数 // one 代表第一个参数 type para1385 struct { arr1 []int arr2 []int d int } // ans 是答案 // one 代表第一个答案 type ans1385 struct { one []int } func Test_Problem1385(t *testing.T) { qs := []question1385{ { para...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0331.Verify-Preorder-Serialization-of-a-Binary-Tree/331. Verify Preorder Serialization of a Binary Tree.go
leetcode/0331.Verify-Preorder-Serialization-of-a-Binary-Tree/331. Verify Preorder Serialization of a Binary Tree.go
package leetcode import "strings" func isValidSerialization(preorder string) bool { nodes, diff := strings.Split(preorder, ","), 1 for _, node := range nodes { diff-- if diff < 0 { return false } if node != "#" { diff += 2 } } return diff == 0 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0331.Verify-Preorder-Serialization-of-a-Binary-Tree/331. Verify Preorder Serialization of a Binary Tree_test.go
leetcode/0331.Verify-Preorder-Serialization-of-a-Binary-Tree/331. Verify Preorder Serialization of a Binary Tree_test.go
package leetcode import ( "fmt" "testing" ) type question331 struct { para331 ans331 } // para 是参数 // one 代表第一个参数 type para331 struct { one string } // ans 是答案 // one 代表第一个答案 type ans331 struct { one bool } func Test_Problem331(t *testing.T) { qs := []question331{ { para331{"9,3,4,#,#,1,#,#,2,#,6,#,#...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0630.Course-Schedule-III/630. Course Schedule III_test.go
leetcode/0630.Course-Schedule-III/630. Course Schedule III_test.go
package leetcode import ( "fmt" "testing" ) type question630 struct { para630 ans630 } // para 是参数 // one 代表第一个参数 type para630 struct { courses [][]int } // ans 是答案 // one 代表第一个答案 type ans630 struct { one int } func Test_Problem630(t *testing.T) { qs := []question630{ { para630{[][]int{{100, 200}, {2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0630.Course-Schedule-III/630. Course Schedule III.go
leetcode/0630.Course-Schedule-III/630. Course Schedule III.go
package leetcode import ( "container/heap" "sort" ) func scheduleCourse(courses [][]int) int { sort.Slice(courses, func(i, j int) bool { return courses[i][1] < courses[j][1] }) maxHeap, time := &Schedule{}, 0 heap.Init(maxHeap) for _, c := range courses { if time+c[0] <= c[1] { time += c[0] heap.Push...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1201.Ugly-Number-III/1201. Ugly Number III_test.go
leetcode/1201.Ugly-Number-III/1201. Ugly Number III_test.go
package leetcode import ( "fmt" "testing" ) type question1201 struct { para1201 ans1201 } // para 是参数 // one 代表第一个参数 type para1201 struct { n int a int b int c int } // ans 是答案 // one 代表第一个答案 type ans1201 struct { one int } func Test_Problem1201(t *testing.T) { qs := []question1201{ { para1201{3, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1201.Ugly-Number-III/1201. Ugly Number III.go
leetcode/1201.Ugly-Number-III/1201. Ugly Number III.go
package leetcode func nthUglyNumber(n int, a int, b int, c int) int { low, high := int64(0), int64(2*1e9) for low < high { mid := low + (high-low)>>1 if calNthCount(mid, int64(a), int64(b), int64(c)) < int64(n) { low = mid + 1 } else { high = mid } } return int(low) } func calNthCount(num, a, b, c i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1614.Maximum-Nesting-Depth-of-the-Parentheses/1614. Maximum Nesting Depth of the Parentheses.go
leetcode/1614.Maximum-Nesting-Depth-of-the-Parentheses/1614. Maximum Nesting Depth of the Parentheses.go
package leetcode func maxDepth(s string) int { res, cur := 0, 0 for _, c := range s { if c == '(' { cur++ res = max(res, cur) } else if c == ')' { cur-- } } return res } func max(a, b int) int { if a > b { return a } return b }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1614.Maximum-Nesting-Depth-of-the-Parentheses/1614. Maximum Nesting Depth of the Parentheses_test.go
leetcode/1614.Maximum-Nesting-Depth-of-the-Parentheses/1614. Maximum Nesting Depth of the Parentheses_test.go
package leetcode import ( "fmt" "testing" ) type question1614 struct { para1614 ans1614 } // para 是参数 // one 代表第一个参数 type para1614 struct { p string } // ans 是答案 // one 代表第一个答案 type ans1614 struct { one int } func Test_Problem1614(t *testing.T) { qs := []question1614{ { para1614{"(1+(2*3)+((8)/4))+1"...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0393.UTF-8-Validation/393. UTF-8 Validation.go
leetcode/0393.UTF-8-Validation/393. UTF-8 Validation.go
package leetcode func validUtf8(data []int) bool { count := 0 for _, d := range data { if count == 0 { if d >= 248 { // 11111000 = 248 return false } else if d >= 240 { // 11110000 = 240 count = 3 } else if d >= 224 { // 11100000 = 224 count = 2 } else if d >= 192 { // 11000000 = 192 co...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0393.UTF-8-Validation/393. UTF-8 Validation_test.go
leetcode/0393.UTF-8-Validation/393. UTF-8 Validation_test.go
package leetcode import ( "fmt" "testing" ) type question393 struct { para393 ans393 } // para 是参数 // one 代表第一个参数 type para393 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans393 struct { one bool } func Test_Problem393(t *testing.T) { qs := []question393{ { para393{[]int{197, 130, 1}}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1603.Design-Parking-System/1603. Design Parking System.go
leetcode/1603.Design-Parking-System/1603. Design Parking System.go
package leetcode type ParkingSystem struct { Big int Medium int Small int } func Constructor(big int, medium int, small int) ParkingSystem { return ParkingSystem{ Big: big, Medium: medium, Small: small, } } func (this *ParkingSystem) AddCar(carType int) bool { switch carType { case 1: { if ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1603.Design-Parking-System/1603. Design Parking System_test.go
leetcode/1603.Design-Parking-System/1603. Design Parking System_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem1603(t *testing.T) { obj := Constructor(1, 1, 0) fmt.Printf("obj = %v\n", obj) fmt.Printf("obj = %v\n", obj.AddCar(1)) fmt.Printf("obj = %v\n", obj.AddCar(2)) fmt.Printf("obj = %v\n", obj.AddCar(3)) fmt.Printf("obj = %v\n", obj.AddCar(1)) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0152.Maximum-Product-Subarray/152. Maximum Product Subarray.go
leetcode/0152.Maximum-Product-Subarray/152. Maximum Product Subarray.go
package leetcode func maxProduct(nums []int) int { minimum, maximum, res := nums[0], nums[0], nums[0] for i := 1; i < len(nums); i++ { if nums[i] < 0 { maximum, minimum = minimum, maximum } maximum = max(nums[i], maximum*nums[i]) minimum = min(nums[i], minimum*nums[i]) res = max(res, maximum) } return...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0152.Maximum-Product-Subarray/152. Maximum Product Subarray_test.go
leetcode/0152.Maximum-Product-Subarray/152. Maximum Product Subarray_test.go
package leetcode import ( "fmt" "testing" ) type question152 struct { para152 ans152 } // para 是参数 // one 代表第一个参数 type para152 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans152 struct { one int } func Test_Problem152(t *testing.T) { qs := []question152{ { para152{[]int{-2}}, ans152{-2}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0416.Partition-Equal-Subset-Sum/416. Partition Equal Subset Sum.go
leetcode/0416.Partition-Equal-Subset-Sum/416. Partition Equal Subset Sum.go
package leetcode func canPartition(nums []int) bool { sum := 0 for _, v := range nums { sum += v } if sum%2 != 0 { return false } // C = half sum n, C, dp := len(nums), sum/2, make([]bool, sum/2+1) for i := 0; i <= C; i++ { dp[i] = (nums[0] == i) } for i := 1; i < n; i++ { for j := C; j >= nums[i]; j...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0416.Partition-Equal-Subset-Sum/416. Partition Equal Subset Sum_test.go
leetcode/0416.Partition-Equal-Subset-Sum/416. Partition Equal Subset Sum_test.go
package leetcode import ( "fmt" "testing" ) type question416 struct { para416 ans416 } // para 是参数 // one 代表第一个参数 type para416 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans416 struct { one bool } func Test_Problem416(t *testing.T) { qs := []question416{ { para416{[]int{1, 5, 11, 5}}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1275.Find-Winner-on-a-Tic-Tac-Toe-Game/1275. Find Winner on a Tic Tac Toe Game_test.go
leetcode/1275.Find-Winner-on-a-Tic-Tac-Toe-Game/1275. Find Winner on a Tic Tac Toe Game_test.go
package leetcode import ( "fmt" "testing" ) type question1275 struct { para1275 ans1275 } // para 是参数 // one 代表第一个参数 type para1275 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans1275 struct { one string } func Test_Problem1275(t *testing.T) { qs := []question1275{ { para1275{[][]int{{0, 0},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1275.Find-Winner-on-a-Tic-Tac-Toe-Game/1275. Find Winner on a Tic Tac Toe Game.go
leetcode/1275.Find-Winner-on-a-Tic-Tac-Toe-Game/1275. Find Winner on a Tic Tac Toe Game.go
package leetcode func tictactoe(moves [][]int) string { board := [3][3]byte{} for i := 0; i < len(moves); i++ { if i%2 == 0 { board[moves[i][0]][moves[i][1]] = 'X' } else { board[moves[i][0]][moves[i][1]] = 'O' } } for i := 0; i < 3; i++ { if board[i][0] == 'X' && board[i][1] == 'X' && board[i][2] ==...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0507.Perfect-Number/507. Perfect Number_test.go
leetcode/0507.Perfect-Number/507. Perfect Number_test.go
package leetcode import ( "fmt" "testing" ) type question507 struct { para507 ans507 } // para 是参数 // one 代表第一个参数 type para507 struct { num int } // ans 是答案 // one 代表第一个答案 type ans507 struct { one bool } func Test_Problem507(t *testing.T) { qs := []question507{ { para507{28}, ans507{true}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0507.Perfect-Number/507. Perfect Number.go
leetcode/0507.Perfect-Number/507. Perfect Number.go
package leetcode import "math" // 方法一 func checkPerfectNumber(num int) bool { if num <= 1 { return false } sum, bound := 1, int(math.Sqrt(float64(num)))+1 for i := 2; i < bound; i++ { if num%i != 0 { continue } corrDiv := num / i sum += corrDiv + i } return sum == num } // 方法二 打表 func checkPerfect...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0234.Palindrome-Linked-List/234. Palindrome Linked List_test.go
leetcode/0234.Palindrome-Linked-List/234. Palindrome Linked List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question234 struct { para234 ans234 } // para 是参数 // one 代表第一个参数 type para234 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans234 struct { one bool } func Test_Problem234(t *testing.T) { qs := []question2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0234.Palindrome-Linked-List/234. Palindrome Linked List.go
leetcode/0234.Palindrome-Linked-List/234. Palindrome 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 isPalindrome(head *ListNode) bool { slice := []int{} for he...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array/34. Find First and Last Position of Element in Sorted Array_test.go
leetcode/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array/34. Find First and Last Position of Element in Sorted Array_test.go
package leetcode import ( "fmt" "testing" ) type question34 struct { para34 ans34 } // para 是参数 // one 代表第一个参数 type para34 struct { nums []int target int } // ans 是答案 // one 代表第一个答案 type ans34 struct { one []int } func Test_Problem34(t *testing.T) { qs := []question34{ { para34{[]int{5, 7, 7, 8, 8...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array/34. Find First and Last Position of Element in Sorted Array.go
leetcode/0034.Find-First-and-Last-Position-of-Element-in-Sorted-Array/34. Find First and Last Position of Element in Sorted Array.go
package leetcode func searchRange(nums []int, target int) []int { return []int{searchFirstEqualElement(nums, target), searchLastEqualElement(nums, target)} } // 二分查找第一个与 target 相等的元素,时间复杂度 O(logn) func searchFirstEqualElement(nums []int, target int) int { low, high := 0, len(nums)-1 for low <= high { mid := low...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0709.To-Lower-Case/709. To Lower Case_test.go
leetcode/0709.To-Lower-Case/709. To Lower Case_test.go
package leetcode import ( "fmt" "testing" ) type question709 struct { para709 ans709 } // para 是参数 // one 代表第一个参数 type para709 struct { one string } // ans 是答案 // one 代表第一个答案 type ans709 struct { one string } func Test_Problem709(t *testing.T) { qs := []question709{ { para709{"Hello"}, ans709{"hel...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0709.To-Lower-Case/709. To Lower Case.go
leetcode/0709.To-Lower-Case/709. To Lower Case.go
package leetcode func toLowerCase(s string) string { runes := []rune(s) diff := 'a' - 'A' for i := 0; i < len(s); i++ { if runes[i] >= 'A' && runes[i] <= 'Z' { runes[i] += diff } } return string(runes) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1353.Maximum-Number-of-Events-That-Can-Be-Attended/1353. Maximum Number of Events That Can Be Attended.go
leetcode/1353.Maximum-Number-of-Events-That-Can-Be-Attended/1353. Maximum Number of Events That Can Be Attended.go
package leetcode import ( "sort" ) func maxEvents(events [][]int) int { sort.Slice(events, func(i, j int) bool { if events[i][0] == events[j][0] { return events[i][1] < events[j][1] } return events[i][0] < events[j][0] }) attended, current := 1, events[0] for i := 1; i < len(events); i++ { prev, event...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1353.Maximum-Number-of-Events-That-Can-Be-Attended/1353. Maximum Number of Events That Can Be Attended_test.go
leetcode/1353.Maximum-Number-of-Events-That-Can-Be-Attended/1353. Maximum Number of Events That Can Be Attended_test.go
package leetcode import ( "fmt" "testing" ) type question1353 struct { para1353 ans1353 } // para 是参数 // one 代表第一个参数 type para1353 struct { events [][]int } // ans 是答案 // one 代表第一个答案 type ans1353 struct { one int } func Test_Problem1353(t *testing.T) { qs := []question1353{ { para1353{[][]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/0832.Flipping-an-Image/832. Flipping an Image_test.go
leetcode/0832.Flipping-an-Image/832. Flipping an Image_test.go
package leetcode import ( "fmt" "testing" ) type question832 struct { para832 ans832 } // para 是参数 // one 代表第一个参数 type para832 struct { A [][]int } // ans 是答案 // one 代表第一个答案 type ans832 struct { one [][]int } func Test_Problem832(t *testing.T) { qs := []question832{ { para832{[][]int{{1, 1, 0}, {1, 0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0832.Flipping-an-Image/832. Flipping an Image.go
leetcode/0832.Flipping-an-Image/832. Flipping an Image.go
package leetcode func flipAndInvertImage(A [][]int) [][]int { for i := 0; i < len(A); i++ { for a, b := 0, len(A[i])-1; a < b; a, b = a+1, b-1 { A[i][a], A[i][b] = A[i][b], A[i][a] } for a := 0; a < len(A[i]); a++ { A[i][a] = (A[i][a] + 1) % 2 } } return A }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1464.Maximum-Product-of-Two-Elements-in-an-Array/1464. Maximum Product of Two Elements in an Array_test.go
leetcode/1464.Maximum-Product-of-Two-Elements-in-an-Array/1464. Maximum Product of Two Elements in an Array_test.go
package leetcode import ( "fmt" "testing" ) type question1464 struct { para1464 ans1464 } // para 是参数 // one 代表第一个参数 type para1464 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1464 struct { one int } func Test_Problem1464(t *testing.T) { qs := []question1464{ { para1464{[]int{3, 4, 5, 2}},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1464.Maximum-Product-of-Two-Elements-in-an-Array/1464. Maximum Product of Two Elements in an Array.go
leetcode/1464.Maximum-Product-of-Two-Elements-in-an-Array/1464. Maximum Product of Two Elements in an Array.go
package leetcode func maxProduct(nums []int) int { max1, max2 := 0, 0 for _, num := range nums { if num >= max1 { max2 = max1 max1 = num } else if num <= max1 && num >= max2 { max2 = num } } return (max1 - 1) * (max2 - 1) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0093.Restore-IP-Addresses/93. Restore IP Addresses_test.go
leetcode/0093.Restore-IP-Addresses/93. Restore IP Addresses_test.go
package leetcode import ( "fmt" "testing" ) type question93 struct { para93 ans93 } // para 是参数 // one 代表第一个参数 type para93 struct { s string } // ans 是答案 // one 代表第一个答案 type ans93 struct { one []string } func Test_Problem93(t *testing.T) { qs := []question93{ { para93{"25525511135"}, ans93{[]strin...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0093.Restore-IP-Addresses/93. Restore IP Addresses.go
leetcode/0093.Restore-IP-Addresses/93. Restore IP Addresses.go
package leetcode import ( "strconv" ) func restoreIPAddresses(s string) []string { if s == "" { return []string{} } res, ip := []string{}, []int{} dfs(s, 0, ip, &res) return res } func dfs(s string, index int, ip []int, res *[]string) { if index == len(s) { if len(ip) == 4 { *res = append(*res, getStri...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0901.Online-Stock-Span/901. Online Stock Span.go
leetcode/0901.Online-Stock-Span/901. Online Stock Span.go
package leetcode import "fmt" // node pair type Node struct { Val int res int } // slice type StockSpanner struct { Item []Node } func Constructor901() StockSpanner { stockSpanner := StockSpanner{make([]Node, 0)} return stockSpanner } // need refactor later func (this *StockSpanner) Next(price int) int { res...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0901.Online-Stock-Span/901. Online Stock Span_test.go
leetcode/0901.Online-Stock-Span/901. Online Stock Span_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem901(t *testing.T) { obj := Constructor901() fmt.Printf("obj = %v\n", obj) param1 := obj.Next(100) fmt.Printf("param_1 = %v\n", param1) param2 := obj.Next(80) fmt.Printf("param_2 = %v\n", param2) param3 := obj.Next(60) fmt.Printf("param_3 = %v\n", ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0019.Remove-Nth-Node-From-End-of-List/19. Remove Nth Node From End of List_test.go
leetcode/0019.Remove-Nth-Node-From-End-of-List/19. Remove Nth Node From End of List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question19 struct { para19 ans19 } // para 是参数 // one 代表第一个参数 type para19 struct { one []int n int } // ans 是答案 // one 代表第一个答案 type ans19 struct { one []int } func Test_Problem19(t *testing.T) { qs := []quest...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0019.Remove-Nth-Node-From-End-of-List/19. Remove Nth Node From End of List.go
leetcode/0019.Remove-Nth-Node-From-End-of-List/19. Remove Nth Node From End of 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 removeNthFromEnd(head *ListNode, n int) *ListNode { dummyHea...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0389.Find-the-Difference/389. Find the Difference.go
leetcode/0389.Find-the-Difference/389. Find the Difference.go
package leetcode func findTheDifference(s string, t string) byte { n, ch := len(t), t[len(t)-1] for i := 0; i < n-1; i++ { ch ^= s[i] ch ^= t[i] } return ch }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0389.Find-the-Difference/389. Find the Difference_test.go
leetcode/0389.Find-the-Difference/389. Find the Difference_test.go
package leetcode import ( "fmt" "testing" ) type question389 struct { para389 ans389 } // para 是参数 // one 代表第一个参数 type para389 struct { s string t string } // ans 是答案 // one 代表第一个答案 type ans389 struct { one byte } func Test_Problem389(t *testing.T) { qs := []question389{ { para389{"abcd", "abcde"}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1234.Replace-the-Substring-for-Balanced-String/1234. Replace the Substring for Balanced String_test.go
leetcode/1234.Replace-the-Substring-for-Balanced-String/1234. Replace the Substring for Balanced String_test.go
package leetcode import ( "fmt" "testing" ) type question1234 struct { para1234 ans1234 } // para 是参数 // one 代表第一个参数 type para1234 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1234 struct { one int } func Test_Problem1234(t *testing.T) { qs := []question1234{ { para1234{"QWER"}, ans1234{0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1234.Replace-the-Substring-for-Balanced-String/1234. Replace the Substring for Balanced String.go
leetcode/1234.Replace-the-Substring-for-Balanced-String/1234. Replace the Substring for Balanced String.go
package leetcode func balancedString(s string) int { count, k := make([]int, 128), len(s)/4 for _, v := range s { count[int(v)]++ } left, right, res := 0, -1, len(s) for left < len(s) { if count['Q'] > k || count['W'] > k || count['E'] > k || count['R'] > k { if right+1 < len(s) { right++ count[s[r...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1439.Find-the-Kth-Smallest-Sum-of-a-Matrix-With-Sorted-Rows/1439. Find the Kth Smallest Sum of a Matrix With Sorted Rows_test.go
leetcode/1439.Find-the-Kth-Smallest-Sum-of-a-Matrix-With-Sorted-Rows/1439. Find the Kth Smallest Sum of a Matrix With Sorted Rows_test.go
package leetcode import ( "fmt" "testing" ) type question1439 struct { para1439 ans1439 } // para 是参数 // one 代表第一个参数 type para1439 struct { mat [][]int k int } // ans 是答案 // one 代表第一个答案 type ans1439 struct { one int } func Test_Problem1439(t *testing.T) { qs := []question1439{ { para1439{[][]int{{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1439.Find-the-Kth-Smallest-Sum-of-a-Matrix-With-Sorted-Rows/1439. Find the Kth Smallest Sum of a Matrix With Sorted Rows.go
leetcode/1439.Find-the-Kth-Smallest-Sum-of-a-Matrix-With-Sorted-Rows/1439. Find the Kth Smallest Sum of a Matrix With Sorted Rows.go
package leetcode import "container/heap" func kthSmallest(mat [][]int, k int) int { if len(mat) == 0 || len(mat[0]) == 0 || k == 0 { return 0 } prev := mat[0] for i := 1; i < len(mat); i++ { prev = kSmallestPairs(prev, mat[i], k) } if k < len(prev) { return -1 } return prev[k-1] } func kSmallestPairs(n...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0895.Maximum-Frequency-Stack/895. Maximum Frequency Stack.go
leetcode/0895.Maximum-Frequency-Stack/895. Maximum Frequency Stack.go
package leetcode type FreqStack struct { freq map[int]int group map[int][]int maxfreq int } func Constructor895() FreqStack { hash := make(map[int]int) maxHash := make(map[int][]int) return FreqStack{freq: hash, group: maxHash} } func (this *FreqStack) Push(x int) { if _, ok := this.freq[x]; ok { this....
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0895.Maximum-Frequency-Stack/895. Maximum Frequency Stack_test.go
leetcode/0895.Maximum-Frequency-Stack/895. Maximum Frequency Stack_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem895(t *testing.T) { obj := Constructor895() fmt.Printf("obj = %v\n", obj) obj.Push(5) fmt.Printf("obj = %v\n", obj) obj.Push(7) fmt.Printf("obj = %v\n", obj) obj.Push(5) fmt.Printf("obj = %v\n", obj) obj.Push(7) fmt.Printf("obj = %v\n", obj) ob...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1691.Maximum-Height-by-Stacking-Cuboids/1691. Maximum Height by Stacking Cuboids_test.go
leetcode/1691.Maximum-Height-by-Stacking-Cuboids/1691. Maximum Height by Stacking Cuboids_test.go
package leetcode import ( "fmt" "testing" ) type question1691 struct { para1691 ans1691 } // para 是参数 // one 代表第一个参数 type para1691 struct { cuboids [][]int } // ans 是答案 // one 代表第一个答案 type ans1691 struct { one int } func Test_Problem1691(t *testing.T) { qs := []question1691{ { para1691{[][]int{{50, 4...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1691.Maximum-Height-by-Stacking-Cuboids/1691. Maximum Height by Stacking Cuboids.go
leetcode/1691.Maximum-Height-by-Stacking-Cuboids/1691. Maximum Height by Stacking Cuboids.go
package leetcode import "sort" func maxHeight(cuboids [][]int) int { n := len(cuboids) for i := 0; i < n; i++ { sort.Ints(cuboids[i]) // 立方体三边内部排序 } // 立方体排序,先按最短边,再到最长边 sort.Slice(cuboids, func(i, j int) bool { if cuboids[i][0] != cuboids[j][0] { return cuboids[i][0] < cuboids[j][0] } if cuboids[i][1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0665.Non-decreasing-Array/665. Non-decreasing Array_test.go
leetcode/0665.Non-decreasing-Array/665. Non-decreasing Array_test.go
package leetcode import ( "fmt" "testing" ) type question665 struct { para665 ans665 } // para 是参数 // one 代表第一个参数 type para665 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans665 struct { one bool } func Test_Problem665(t *testing.T) { qs := []question665{ { para665{[]int{4, 2, 3}}, ans665...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0665.Non-decreasing-Array/665. Non-decreasing Array.go
leetcode/0665.Non-decreasing-Array/665. Non-decreasing Array.go
package leetcode func checkPossibility(nums []int) bool { count := 0 for i := 0; i < len(nums)-1; i++ { if nums[i] > nums[i+1] { count++ if count > 1 { return false } if i > 0 && nums[i+1] < nums[i-1] { nums[i+1] = nums[i] } } } return true }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0263.Ugly-Number/263. Ugly Number_test.go
leetcode/0263.Ugly-Number/263. Ugly Number_test.go
package leetcode import ( "fmt" "testing" ) type question263 struct { para263 ans263 } // para 是参数 // one 代表第一个参数 type para263 struct { one int } // ans 是答案 // one 代表第一个答案 type ans263 struct { one bool } func Test_Problem263(t *testing.T) { qs := []question263{ { para263{6}, ans263{true}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0263.Ugly-Number/263. Ugly Number.go
leetcode/0263.Ugly-Number/263. Ugly Number.go
package leetcode func isUgly(num int) bool { if num > 0 { for _, i := range []int{2, 3, 5} { for num%i == 0 { num /= i } } } return num == 1 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0766.Toeplitz-Matrix/766. Toeplitz Matrix_test.go
leetcode/0766.Toeplitz-Matrix/766. Toeplitz Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question766 struct { para766 ans766 } // para 是参数 // one 代表第一个参数 type para766 struct { A [][]int } // ans 是答案 // one 代表第一个答案 type ans766 struct { B bool } func Test_Problem766(t *testing.T) { qs := []question766{ { para766{[][]int{{1, 2, 3, 4}, {5, 1, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0766.Toeplitz-Matrix/766. Toeplitz Matrix.go
leetcode/0766.Toeplitz-Matrix/766. Toeplitz Matrix.go
package leetcode func isToeplitzMatrix(matrix [][]int) bool { rows, columns := len(matrix), len(matrix[0]) for i := 1; i < rows; i++ { for j := 1; j < columns; j++ { if matrix[i-1][j-1] != matrix[i][j] { return false } } } return true }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1551.Minimum-Operations-to-Make-Array-Equal/1551. Minimum Operations to Make Array Equal.go
leetcode/1551.Minimum-Operations-to-Make-Array-Equal/1551. Minimum Operations to Make Array Equal.go
package leetcode func minOperations(n int) int { return n * n / 4 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1551.Minimum-Operations-to-Make-Array-Equal/1551. Minimum Operations to Make Array Equal_test.go
leetcode/1551.Minimum-Operations-to-Make-Array-Equal/1551. Minimum Operations to Make Array Equal_test.go
package leetcode import ( "fmt" "testing" ) type question1551 struct { para1551 ans1551 } // para 是参数 // one 代表第一个参数 type para1551 struct { n int } // ans 是答案 // one 代表第一个答案 type ans1551 struct { one int } func Test_Problem1551(t *testing.T) { qs := []question1551{ { para1551{3}, ans1551{2}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1725.Number-Of-Rectangles-That-Can-Form-The-Largest-Square/1725. Number Of Rectangles That Can Form The Largest Square_test.go
leetcode/1725.Number-Of-Rectangles-That-Can-Form-The-Largest-Square/1725. Number Of Rectangles That Can Form The Largest Square_test.go
package leetcode import ( "fmt" "testing" ) type question1725 struct { para1725 ans1725 } // para 是参数 // one 代表第一个参数 type para1725 struct { rectangles [][]int } // ans 是答案 // one 代表第一个答案 type ans1725 struct { one int } func Test_Problem1725(t *testing.T) { qs := []question1725{ { para1725{[][]int{{5,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1725.Number-Of-Rectangles-That-Can-Form-The-Largest-Square/1725. Number Of Rectangles That Can Form The Largest Square.go
leetcode/1725.Number-Of-Rectangles-That-Can-Form-The-Largest-Square/1725. Number Of Rectangles That Can Form The Largest Square.go
package leetcode func countGoodRectangles(rectangles [][]int) int { minLength, count := 0, 0 for i := range rectangles { minSide := 0 if rectangles[i][0] <= rectangles[i][1] { minSide = rectangles[i][0] } else { minSide = rectangles[i][1] } if minSide > minLength { minLength = minSide count = 1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0434.Number-of-Segments-in-a-String/434.Number of Segments in a String_test.go
leetcode/0434.Number-of-Segments-in-a-String/434.Number of Segments in a String_test.go
package leetcode import ( "fmt" "testing" ) type question434 struct { para434 ans434 } // s 是参数 type para434 struct { s string } // ans 是答案 type ans434 struct { ans int } func Test_Problem434(t *testing.T) { qs := []question434{ { para434{"Hello, my name is John"}, ans434{5}, }, { para434{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0434.Number-of-Segments-in-a-String/434.Number of Segments in a String.go
leetcode/0434.Number-of-Segments-in-a-String/434.Number of Segments in a String.go
package leetcode func countSegments(s string) int { segments := false cnt := 0 for _, v := range s { if v == ' ' && segments { segments = false cnt += 1 } else if v != ' ' { segments = true } } if segments { cnt++ } return cnt }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false