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/0693.Binary-Number-with-Alternating-Bits/693. Binary Number with Alternating Bits_test.go
leetcode/0693.Binary-Number-with-Alternating-Bits/693. Binary Number with Alternating Bits_test.go
package leetcode import ( "fmt" "testing" ) type question693 struct { para693 ans693 } // para 是参数 // one 代表第一个参数 type para693 struct { one int } // ans 是答案 // one 代表第一个答案 type ans693 struct { one bool } func Test_Problem693(t *testing.T) { qs := []question693{ { para693{5}, ans693{true}, }, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0693.Binary-Number-with-Alternating-Bits/693. Binary Number with Alternating Bits.go
leetcode/0693.Binary-Number-with-Alternating-Bits/693. Binary Number with Alternating Bits.go
package leetcode // 解法一 func hasAlternatingBits(n int) bool { /* n = 1 0 1 0 1 0 1 0 n >> 1 0 1 0 1 0 1 0 1 n ^ n>>1 1 1 1 1 1 1 1 1 n 1 1 1 1 1 1 1 1 n + 1 1 0 0 0 0 0 0 0 0 n & (n+1) 0 0 0 0 0 0 0 0 */ n = n ^ (n >> 1) return (n & (n + 1)) == 0 } // 解法二 fu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0372.Super-Pow/372. Super Pow_test.go
leetcode/0372.Super-Pow/372. Super Pow_test.go
package leetcode import ( "fmt" "testing" ) type question372 struct { para372 ans372 } // para 是参数 // one 代表第一个参数 type para372 struct { a int b []int } // ans 是答案 // one 代表第一个答案 type ans372 struct { one int } func Test_Problem372(t *testing.T) { qs := []question372{ { para372{2, []int{3}}, ans372...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0372.Super-Pow/372. Super Pow.go
leetcode/0372.Super-Pow/372. Super Pow.go
package leetcode // 解法一 快速幂 res = res^10 * qpow(a, b[i]) // 模运算性质一:(a + b) % p = (a % p + b % p) % p // 模运算性质二:(a - b) % p = (a % p - b % p + p) % p // 模运算性质三:(a * b) % p = (a % p * b % p) % p // 模运算性质四:a ^ b % p = ((a % p)^b) % p // 模运算性质五:ab % p = ((a % p) * ( b % p)) % p, 其中 ab 是一个数字,如:2874,98374 等等 // 举个例子 // 1234...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0096.Unique-Binary-Search-Trees/96. Unique Binary Search Trees.go
leetcode/0096.Unique-Binary-Search-Trees/96. Unique Binary Search Trees.go
package leetcode func numTrees(n int) int { dp := make([]int, n+1) dp[0], dp[1] = 1, 1 for i := 2; i <= n; i++ { for j := 1; j <= i; j++ { dp[i] += dp[j-1] * dp[i-j] } } 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/0096.Unique-Binary-Search-Trees/96. Unique Binary Search Trees_test.go
leetcode/0096.Unique-Binary-Search-Trees/96. Unique Binary Search Trees_test.go
package leetcode import ( "fmt" "testing" ) type question96 struct { para96 ans96 } // para 是参数 // one 代表第一个参数 type para96 struct { one int } // ans 是答案 // one 代表第一个答案 type ans96 struct { one int } func Test_Problem96(t *testing.T) { qs := []question96{ { para96{1}, ans96{1}, }, { para96{3...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0399.Evaluate-Division/399. Evaluate Division_test.go
leetcode/0399.Evaluate-Division/399. Evaluate Division_test.go
package leetcode import ( "fmt" "testing" ) type question399 struct { para399 ans399 } // para 是参数 // one 代表第一个参数 type para399 struct { e [][]string v []float64 q [][]string } // ans 是答案 // one 代表第一个答案 type ans399 struct { one []float64 } func Test_Problem399(t *testing.T) { qs := []question399{ { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0399.Evaluate-Division/399. Evaluate Division.go
leetcode/0399.Evaluate-Division/399. Evaluate Division.go
package leetcode type stringUnionFind struct { parents map[string]string vals map[string]float64 } func (suf stringUnionFind) add(x string) { if _, ok := suf.parents[x]; ok { return } suf.parents[x] = x suf.vals[x] = 1.0 } func (suf stringUnionFind) find(x string) string { p := "" if v, ok := suf.parent...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1003.Check-If-Word-Is-Valid-After-Substitutions/1003. Check If Word Is Valid After Substitutions_test.go
leetcode/1003.Check-If-Word-Is-Valid-After-Substitutions/1003. Check If Word Is Valid After Substitutions_test.go
package leetcode import ( "fmt" "testing" ) type question1003 struct { para1003 ans1003 } // para 是参数 // one 代表第一个参数 type para1003 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1003 struct { one bool } func Test_Problem1003(t *testing.T) { qs := []question1003{ { para1003{"aabcbc"}, ans100...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1003.Check-If-Word-Is-Valid-After-Substitutions/1003. Check If Word Is Valid After Substitutions.go
leetcode/1003.Check-If-Word-Is-Valid-After-Substitutions/1003. Check If Word Is Valid After Substitutions.go
package leetcode func isValid1003(S string) bool { if len(S) < 3 { return false } stack := []byte{} for i := 0; i < len(S); i++ { if S[i] == 'a' { stack = append(stack, S[i]) } else if S[i] == 'b' { if len(stack) > 0 && stack[len(stack)-1] == 'a' { stack = append(stack, S[i]) } else { return...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0821.Shortest-Distance-to-a-Character/821. Shortest Distance to a Character_test.go
leetcode/0821.Shortest-Distance-to-a-Character/821. Shortest Distance to a Character_test.go
package leetcode import ( "fmt" "testing" ) type question821 struct { para821 ans821 } // para 是参数 // one 代表第一个参数 type para821 struct { s string c byte } // ans 是答案 // one 代表第一个答案 type ans821 struct { one []int } func Test_Problem821(t *testing.T) { qs := []question821{ { para821{"loveleetcode", 'e'...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0821.Shortest-Distance-to-a-Character/821. Shortest Distance to a Character.go
leetcode/0821.Shortest-Distance-to-a-Character/821. Shortest Distance to a Character.go
package leetcode import ( "math" ) // 解法一 func shortestToChar(s string, c byte) []int { n := len(s) res := make([]int, n) for i := range res { res[i] = n } for i := 0; i < n; i++ { if s[i] == c { res[i] = 0 } else if i > 0 { res[i] = res[i-1] + 1 } } for i := n - 1; i >= 0; i-- { if i < n-1 &&...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0958.Check-Completeness-of-a-Binary-Tree/0958.Check Completeness of a Binary Tree.go
leetcode/0958.Check-Completeness-of-a-Binary-Tree/0958.Check Completeness of a Binary Tree.go
package leetcode import ( "github.com/halfrost/LeetCode-Go/structures" ) // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func isCompleteTree(root *TreeNode) bool { queue,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0958.Check-Completeness-of-a-Binary-Tree/0958.Check Completeness of a Binary Tree_test.go
leetcode/0958.Check-Completeness-of-a-Binary-Tree/0958.Check Completeness of a Binary Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question958 struct { para958 ans958 } // para 是参数 // one 代表第一个参数 type para958 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans958 struct { one bool } func Test_Problem958(t *testing.T) { qs := []question9...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0260.Single-Number-III/260. Single Number III.go
leetcode/0260.Single-Number-III/260. Single Number III.go
package leetcode func singleNumberIII(nums []int) []int { diff := 0 for _, num := range nums { diff ^= num } // Get its last set bit (lsb) diff &= -diff res := []int{0, 0} // this array stores the two numbers we will return for _, num := range nums { if (num & diff) == 0 { // the bit is not set res[0] ^=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0260.Single-Number-III/260. Single Number III_test.go
leetcode/0260.Single-Number-III/260. Single Number III_test.go
package leetcode import ( "fmt" "testing" ) type question260 struct { para260 ans260 } // para 是参数 // one 代表第一个参数 type para260 struct { s []int } // ans 是答案 // one 代表第一个答案 type ans260 struct { one []int } func Test_Problem260(t *testing.T) { qs := []question260{ { para260{[]int{1, 2, 1, 3, 2, 5}}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0116.Populating-Next-Right-Pointers-in-Each-Node/116.Populating Next Right Pointers in Each Node.go
leetcode/0116.Populating-Next-Right-Pointers-in-Each-Node/116.Populating Next Right Pointers in Each Node.go
package leetcode type Node struct { Val int Left *Node Right *Node Next *Node } // 解法一:迭代 func connect(root *Node) *Node { if root == nil { return root } q := []*Node{root} for len(q) > 0 { var p []*Node // 遍历这一层的所有节点 for i, node := range q { if i+1 < len(q) { node.Next = q[i+1] } if ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0116.Populating-Next-Right-Pointers-in-Each-Node/116.Populating Next Right Pointers in Each Node_test.go
leetcode/0116.Populating-Next-Right-Pointers-in-Each-Node/116.Populating Next Right Pointers in Each Node_test.go
package leetcode import ( "fmt" "testing" ) type question116 struct { para116 ans116 } // para 是参数 // one 代表第一个参数 type para116 struct { one *Node } // ans 是答案 // one 代表第一个答案 type ans116 struct { one *Node } func newQuestionNode() *Node { node7 := &Node{} node7.Val = 7 node6 := &Node{} node6.Val = 6 no...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0162.Find-Peak-Element/162. Find Peak Element.go
leetcode/0162.Find-Peak-Element/162. Find Peak Element.go
package leetcode // 解法一 二分 func findPeakElement(nums []int) int { if len(nums) == 0 || len(nums) == 1 { return 0 } low, high := 0, len(nums)-1 for low <= high { mid := low + (high-low)>>1 if (mid == len(nums)-1 && nums[mid-1] < nums[mid]) || (mid > 0 && nums[mid-1] < nums[mid] && (mid <= len(nums)-2 && nums[...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0162.Find-Peak-Element/162. Find Peak Element_test.go
leetcode/0162.Find-Peak-Element/162. Find Peak Element_test.go
package leetcode import ( "fmt" "testing" ) type question162 struct { para162 ans162 } // para 是参数 // one 代表第一个参数 type para162 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans162 struct { one int } func Test_Problem162(t *testing.T) { qs := []question162{ { para162{[]int{2, 1, 2}}, ans162{0...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0922.Sort-Array-By-Parity-II/922. Sort Array By Parity II.go
leetcode/0922.Sort-Array-By-Parity-II/922. Sort Array By Parity II.go
package leetcode func sortArrayByParityII(A []int) []int { if len(A) == 0 || len(A)%2 != 0 { return []int{} } res := make([]int, len(A)) oddIndex := 1 evenIndex := 0 for i := 0; i < len(A); i++ { if A[i]%2 == 0 { res[evenIndex] = A[i] evenIndex += 2 } else { res[oddIndex] = A[i] oddIndex += 2 ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0922.Sort-Array-By-Parity-II/922. Sort Array By Parity II_test.go
leetcode/0922.Sort-Array-By-Parity-II/922. Sort Array By Parity II_test.go
package leetcode import ( "fmt" "testing" ) type question922 struct { para922 ans922 } // para 是参数 // one 代表第一个参数 type para922 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans922 struct { one []int } func Test_Problem922(t *testing.T) { qs := []question922{ { para922{[]int{}}, ans922{[]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer/1290. Convert Binary Number in a Linked List to Integer_test.go
leetcode/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer/1290. Convert Binary Number in a Linked List to Integer_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question1290 struct { para1290 ans1290 } // para 是参数 // one 代表第一个参数 type para1290 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans1290 struct { one int } func Test_Problem1290(t *testing.T) { qs := []ques...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer/1290. Convert Binary Number in a Linked List to Integer.go
leetcode/1290.Convert-Binary-Number-in-a-Linked-List-to-Integer/1290. Convert Binary Number in a Linked List to Integer.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 getDecimalValue(head *ListNode) int { sum := 0 for head != nil { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value.go
leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value.go
package leetcode // 解法一 贪心 func getSmallestString(n int, k int) string { str, i, j := make([]byte, n), 0, 0 for i = n - 1; i <= k-26; i, k = i-1, k-26 { str[i] = 'z' } if i >= 0 { str[i] = byte('a' + k - 1 - i) for ; j < i; j++ { str[j] = 'a' } } return string(str) } // 解法二 DFS func getSmallestString...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value_test.go
leetcode/1663.Smallest-String-With-A-Given-Numeric-Value/1663. Smallest String With A Given Numeric Value_test.go
package leetcode import ( "fmt" "testing" ) type question1663 struct { para1663 ans1663 } // para 是参数 // one 代表第一个参数 type para1663 struct { n int k int } // ans 是答案 // one 代表第一个答案 type ans1663 struct { one string } func Test_Problem1663(t *testing.T) { qs := []question1663{ { para1663{3, 27}, ans...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth.go
leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth.go
package leetcode func maximumWealth(accounts [][]int) int { res := 0 for _, banks := range accounts { sAmount := 0 for _, amount := range banks { sAmount += amount } if sAmount > res { res = sAmount } } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth_test.go
leetcode/1672.Richest-Customer-Wealth/1672. Richest Customer Wealth_test.go
package leetcode import ( "fmt" "testing" ) type question1672 struct { para1672 ans1672 } // para 是参数 // one 代表第一个参数 type para1672 struct { accounts [][]int } // ans 是答案 // one 代表第一个答案 type ans1672 struct { one int } func Test_Problem1672(t *testing.T) { qs := []question1672{ { para1672{[][]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/1438.Longest-Continuous-Subarray-With-Absolute-Diff-Less-Than-or-Equal-to-Limit/1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit.go
leetcode/1438.Longest-Continuous-Subarray-With-Absolute-Diff-Less-Than-or-Equal-to-Limit/1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit.go
package leetcode func longestSubarray(nums []int, limit int) int { minStack, maxStack, left, res := []int{}, []int{}, 0, 0 for right, num := range nums { for len(minStack) > 0 && nums[minStack[len(minStack)-1]] > num { minStack = minStack[:len(minStack)-1] } minStack = append(minStack, right) for len(maxS...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1438.Longest-Continuous-Subarray-With-Absolute-Diff-Less-Than-or-Equal-to-Limit/1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit_test.go
leetcode/1438.Longest-Continuous-Subarray-With-Absolute-Diff-Less-Than-or-Equal-to-Limit/1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit_test.go
package leetcode import ( "fmt" "testing" ) type question1438 struct { para1438 ans1438 } // para 是参数 // one 代表第一个参数 type para1438 struct { nums []int limit int } // ans 是答案 // one 代表第一个答案 type ans1438 struct { one int } func Test_Problem1438(t *testing.T) { qs := []question1438{ { para1438{[]int{8...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0144.Binary-Tree-Preorder-Traversal/144. Binary Tree Preorder Traversal_test.go
leetcode/0144.Binary-Tree-Preorder-Traversal/144. Binary Tree Preorder Traversal_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question144 struct { para144 ans144 } // para 是参数 // one 代表第一个参数 type para144 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans144 struct { one []int } func Test_Problem144(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/0144.Binary-Tree-Preorder-Traversal/144. Binary Tree Preorder Traversal.go
leetcode/0144.Binary-Tree-Preorder-Traversal/144. Binary Tree 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 preorderTraversal(root *TreeNode) [...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0074.Search-a-2D-Matrix/74. Search a 2D Matrix.go
leetcode/0074.Search-a-2D-Matrix/74. Search a 2D Matrix.go
package leetcode func searchMatrix(matrix [][]int, target int) bool { if len(matrix) == 0 { return false } m, low, high := len(matrix[0]), 0, len(matrix[0])*len(matrix)-1 for low <= high { mid := low + (high-low)>>1 if matrix[mid/m][mid%m] == target { return true } else if matrix[mid/m][mid%m] > target ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0074.Search-a-2D-Matrix/74. Search a 2D Matrix_test.go
leetcode/0074.Search-a-2D-Matrix/74. Search a 2D Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question74 struct { para74 ans74 } // para 是参数 // one 代表第一个参数 type para74 struct { matrix [][]int target int } // ans 是答案 // one 代表第一个答案 type ans74 struct { one bool } func Test_Problem74(t *testing.T) { qs := []question74{ { para74{[][]int{{1, 3, 5, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0701.Insert-into-a-Binary-Search-Tree/701. Insert into a Binary Search Tree.go
leetcode/0701.Insert-into-a-Binary-Search-Tree/701. Insert into a Binary Search Tree.go
package leetcode import "github.com/halfrost/LeetCode-Go/structures" // TreeNode define type TreeNode = structures.TreeNode /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func insert(n *TreeNode, val int) *TreeNode { if n == n...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0701.Insert-into-a-Binary-Search-Tree/701. Insert into a Binary Search Tree_test.go
leetcode/0701.Insert-into-a-Binary-Search-Tree/701. Insert into a Binary Search Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question701 struct { para701 ans701 } // para 是参数 // one 代表第一个参数 type para701 struct { root []int val int } // ans 是答案 // one 代表第一个答案 type ans701 struct { one []int } func Test_Problem701(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/1190.Reverse-Substrings-Between-Each-Pair-of-Parentheses/1190. Reverse Substrings Between Each Pair of Parentheses.go
leetcode/1190.Reverse-Substrings-Between-Each-Pair-of-Parentheses/1190. Reverse Substrings Between Each Pair of Parentheses.go
package leetcode func reverseParentheses(s string) string { pair, stack := make([]int, len(s)), []int{} for i, b := range s { if b == '(' { stack = append(stack, i) } else if b == ')' { j := stack[len(stack)-1] stack = stack[:len(stack)-1] pair[i], pair[j] = j, i } } res := []byte{} for i, step ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1190.Reverse-Substrings-Between-Each-Pair-of-Parentheses/1190. Reverse Substrings Between Each Pair of Parentheses_test.go
leetcode/1190.Reverse-Substrings-Between-Each-Pair-of-Parentheses/1190. Reverse Substrings Between Each Pair of Parentheses_test.go
package leetcode import ( "fmt" "testing" ) type question1190 struct { para1190 ans1190 } // para 是参数 // one 代表第一个参数 type para1190 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1190 struct { one string } func Test_Problem1190(t *testing.T) { qs := []question1190{ { para1190{"(abcd)"}, ans1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent_test.go
leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent_test.go
package leetcode import ( "fmt" "testing" ) type question1662 struct { para1662 ans1662 } // para 是参数 // one 代表第一个参数 type para1662 struct { word1 []string word2 []string } // ans 是答案 // one 代表第一个答案 type ans1662 struct { one bool } func Test_Problem1662(t *testing.T) { qs := []question1662{ { para166...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent.go
leetcode/1662.Check-If-Two-String-Arrays-are-Equivalent/1662. Check If Two String Arrays are Equivalent.go
package leetcode func arrayStringsAreEqual(word1 []string, word2 []string) bool { str1, str2 := "", "" for i := 0; i < len(word1); i++ { str1 += word1[i] } for i := 0; i < len(word2); i++ { str2 += word2[i] } return str1 == str2 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0114.Flatten-Binary-Tree-to-Linked-List/114. Flatten Binary Tree to Linked List_test.go
leetcode/0114.Flatten-Binary-Tree-to-Linked-List/114. Flatten Binary Tree to Linked List_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question114 struct { para114 ans114 } // para 是参数 // one 代表第一个参数 type para114 struct { one []string } // ans 是答案 // one 代表第一个答案 type ans114 struct { one []string } func Test_Problem114(t *testing.T) { qs := []qu...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0114.Flatten-Binary-Tree-to-Linked-List/114. Flatten Binary Tree to Linked List.go
leetcode/0114.Flatten-Binary-Tree-to-Linked-List/114. Flatten Binary Tree to Linked List.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 flatten(root *TreeNode) { list :=...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0605.Can-Place-Flowers/605. Can Place Flowers_test.go
leetcode/0605.Can-Place-Flowers/605. Can Place Flowers_test.go
package leetcode import ( "fmt" "testing" ) type question605 struct { para605 ans605 } // para 是参数 // one 代表第一个参数 type para605 struct { flowerbed []int n int } // ans 是答案 // one 代表第一个答案 type ans605 struct { one bool } func Test_Problem605(t *testing.T) { qs := []question605{ { para605{[]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0605.Can-Place-Flowers/605. Can Place Flowers.go
leetcode/0605.Can-Place-Flowers/605. Can Place Flowers.go
package leetcode func canPlaceFlowers(flowerbed []int, n int) bool { lenth := len(flowerbed) for i := 0; i < lenth && n > 0; i += 2 { if flowerbed[i] == 0 { if i+1 == lenth || flowerbed[i+1] == 0 { n-- } else { i++ } } } if n == 0 { return true } return false }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0109.Convert-Sorted-List-to-Binary-Search-Tree/109. Convert Sorted List to Binary Search Tree_test.go
leetcode/0109.Convert-Sorted-List-to-Binary-Search-Tree/109. Convert Sorted List to Binary Search Tree_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question109 struct { para109 ans109 } // para 是参数 // one 代表第一个参数 type para109 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans109 struct { one []int } func Test_Problem109(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/0109.Convert-Sorted-List-to-Binary-Search-Tree/109. Convert Sorted List to Binary Search Tree.go
leetcode/0109.Convert-Sorted-List-to-Binary-Search-Tree/109. Convert Sorted List to Binary Search Tree.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 * } */ // TreeNode define type TreeNode = structures.TreeNode /** * Definition...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs_test.go
leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs_test.go
package leetcode import ( "fmt" "testing" ) type question1512 struct { para1512 ans1512 } // para 是参数 // one 代表第一个参数 type para1512 struct { nums []int } // ans 是答案 // one 代表第一个答案 type ans1512 struct { one int } func Test_Problem1512(t *testing.T) { qs := []question1512{ { para1512{[]int{1, 2, 3, 1, 1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs.go
leetcode/1512.Number-of-Good-Pairs/1512. Number of Good Pairs.go
package leetcode func numIdenticalPairs(nums []int) int { total := 0 for x := 0; x < len(nums); x++ { for y := x + 1; y < len(nums); y++ { if nums[x] == nums[y] { total++ } } } return total }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0006.ZigZag-Conversion/6. ZigZag Conversion_test.go
leetcode/0006.ZigZag-Conversion/6. ZigZag Conversion_test.go
package leetcode import ( "fmt" "testing" ) type question6 struct { para6 ans6 } // para 是参数 // one 代表第一个参数 type para6 struct { s string numRows int } // ans 是答案 // one 代表第一个答案 type ans6 struct { one string } func Test_Problem6(t *testing.T) { qs := []question6{ { para6{"PAYPALISHIRING", 3}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0006.ZigZag-Conversion/6. ZigZag Conversion.go
leetcode/0006.ZigZag-Conversion/6. ZigZag Conversion.go
package leetcode func convert(s string, numRows int) string { matrix, down, up := make([][]byte, numRows, numRows), 0, numRows-2 for i := 0; i != len(s); { if down != numRows { matrix[down] = append(matrix[down], byte(s[i])) down++ i++ } else if up > 0 { matrix[up] = append(matrix[up], byte(s[i])) ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0124.Binary-Tree-Maximum-Path-Sum/124. Binary Tree Maximum Path Sum_test.go
leetcode/0124.Binary-Tree-Maximum-Path-Sum/124. Binary Tree Maximum Path Sum_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question124 struct { para124 ans124 } // para 是参数 // one 代表第一个参数 type para124 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans124 struct { one int } func Test_Problem124(t *testing.T) { qs := []question12...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0124.Binary-Tree-Maximum-Path-Sum/124. Binary Tree Maximum Path Sum.go
leetcode/0124.Binary-Tree-Maximum-Path-Sum/124. Binary Tree Maximum Path Sum.go
package leetcode import ( "math" "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 maxPathSum(root *TreeNode) int { if...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0530.Minimum-Absolute-Difference-in-BST/530. Minimum Absolute Difference in BST.go
leetcode/0530.Minimum-Absolute-Difference-in-BST/530. Minimum Absolute Difference in BST.go
package leetcode import ( "math" "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 getMinimumDifference(root *TreeNode)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0530.Minimum-Absolute-Difference-in-BST/530. Minimum Absolute Difference in BST_test.go
leetcode/0530.Minimum-Absolute-Difference-in-BST/530. Minimum Absolute Difference in BST_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question530 struct { para530 ans530 } // para 是参数 // one 代表第一个参数 type para530 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans530 struct { one int } func Test_Problem530(t *testing.T) { qs := []question53...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0410.Split-Array-Largest-Sum/410. Split Array Largest Sum.go
leetcode/0410.Split-Array-Largest-Sum/410. Split Array Largest Sum.go
package leetcode func splitArray(nums []int, m int) int { maxNum, sum := 0, 0 for _, num := range nums { sum += num if num > maxNum { maxNum = num } } if m == 1 { return sum } low, high := maxNum, sum for low < high { mid := low + (high-low)>>1 if calSum(mid, m, nums) { high = mid } else { ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0410.Split-Array-Largest-Sum/410. Split Array Largest Sum_test.go
leetcode/0410.Split-Array-Largest-Sum/410. Split Array Largest Sum_test.go
package leetcode import ( "fmt" "testing" ) type question410 struct { para410 ans410 } // para 是参数 // one 代表第一个参数 type para410 struct { nums []int m int } // ans 是答案 // one 代表第一个答案 type ans410 struct { one int } func Test_Problem410(t *testing.T) { qs := []question410{ { para410{[]int{7, 2, 5, 10...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0589.N-ary-Tree-Preorder-Traversal/589. N-ary Tree Preorder Traversal.go
leetcode/0589.N-ary-Tree-Preorder-Traversal/589. N-ary Tree Preorder Traversal.go
package leetcode // Definition for a Node. type Node struct { Val int Children []*Node } // 解法一 非递归 func preorder(root *Node) []int { res := []int{} if root == nil { return res } stack := []*Node{root} for len(stack) > 0 { r := stack[len(stack)-1] stack = stack[:len(stack)-1] res = append(res, r.V...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0589.N-ary-Tree-Preorder-Traversal/589. N-ary Tree Preorder Traversal_test.go
leetcode/0589.N-ary-Tree-Preorder-Traversal/589. N-ary Tree Preorder Traversal_test.go
package leetcode import ( "fmt" "testing" "github.com/halfrost/LeetCode-Go/structures" ) type question589 struct { para589 ans589 } // para 是参数 // one 代表第一个参数 type para589 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans589 struct { one []int } func Test_Problem589(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/0384.Shuffle-an-Array/384.Shuffle an Array.go
leetcode/0384.Shuffle-an-Array/384.Shuffle an Array.go
package leetcode import "math/rand" type Solution struct { nums []int } func Constructor(nums []int) Solution { return Solution{ nums: nums, } } /** Resets the array to its original configuration and return it. */ func (this *Solution) Reset() []int { return this.nums } /** Returns a random shuffling of the ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0384.Shuffle-an-Array/384.Shuffle an Array_test.go
leetcode/0384.Shuffle-an-Array/384.Shuffle an Array_test.go
package leetcode import ( "fmt" "testing" ) type question384 struct { para384 ans384 } // para 是参数 type para384 struct { ops []string value [][]int } // ans 是答案 type ans384 struct { ans [][]int } func Test_Problem384(t *testing.T) { qs := []question384{ { para384{ops: []string{"Solution", "shuffle...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0720.Longest-Word-in-Dictionary/720. Longest Word in Dictionary.go
leetcode/0720.Longest-Word-in-Dictionary/720. Longest Word in Dictionary.go
package leetcode import ( "sort" ) func longestWord(words []string) string { sort.Strings(words) mp := make(map[string]bool) var res string for _, word := range words { size := len(word) if size == 1 || mp[word[:size-1]] { if size > len(res) { res = word } mp[word] = true } } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0720.Longest-Word-in-Dictionary/720. Longest Word in Dictionary_test.go
leetcode/0720.Longest-Word-in-Dictionary/720. Longest Word in Dictionary_test.go
package leetcode import ( "fmt" "testing" ) type question720 struct { para720 ans720 } // para 是参数 // one 代表第一个参数 type para720 struct { w []string } // ans 是答案 // one 代表第一个答案 type ans720 struct { one string } func Test_Problem720(t *testing.T) { qs := []question720{ { para720{[]string{"w", "wo", "wor...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0542.01-Matrix/542. 01 Matrix_test.go
leetcode/0542.01-Matrix/542. 01 Matrix_test.go
package leetcode import ( "fmt" "testing" ) type question542 struct { para542 ans542 } // para 是参数 // one 代表第一个参数 type para542 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans542 struct { one [][]int } func Test_Problem542(t *testing.T) { qs := []question542{ { para542{[][]int{{0, 0, 0}, {0,...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0542.01-Matrix/542. 01 Matrix.go
leetcode/0542.01-Matrix/542. 01 Matrix.go
package leetcode import ( "math" ) // 解法一 BFS func updateMatrixBFS(matrix [][]int) [][]int { res := make([][]int, len(matrix)) if len(matrix) == 0 || len(matrix[0]) == 0 { return res } queue := make([][]int, 0) for i := range matrix { res[i] = make([]int, len(matrix[0])) for j := range res[i] { if matr...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1704.Determine-if-String-Halves-Are-Alike/1704. Determine if String Halves Are Alike.go
leetcode/1704.Determine-if-String-Halves-Are-Alike/1704. Determine if String Halves Are Alike.go
package leetcode func halvesAreAlike(s string) bool { return numVowels(s[len(s)/2:]) == numVowels(s[:len(s)/2]) } func numVowels(x string) int { res := 0 for _, c := range x { switch c { case 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U': res++ } } return res }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1704.Determine-if-String-Halves-Are-Alike/1704. Determine if String Halves Are Alike_test.go
leetcode/1704.Determine-if-String-Halves-Are-Alike/1704. Determine if String Halves Are Alike_test.go
package leetcode import ( "fmt" "testing" ) type question1704 struct { para1704 ans1704 } // para 是参数 // one 代表第一个参数 type para1704 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1704 struct { one bool } func Test_Problem1704(t *testing.T) { qs := []question1704{ { para1704{"book"}, ans1704{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0447.Number-of-Boomerangs/447. Number of Boomerangs_test.go
leetcode/0447.Number-of-Boomerangs/447. Number of Boomerangs_test.go
package leetcode import ( "fmt" "testing" ) type question447 struct { para447 ans447 } // para 是参数 // one 代表第一个参数 type para447 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans447 struct { one int } func Test_Problem447(t *testing.T) { qs := []question447{ { para447{[][]int{{0, 0}, {1, 0}, {2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0447.Number-of-Boomerangs/447. Number of Boomerangs.go
leetcode/0447.Number-of-Boomerangs/447. Number of Boomerangs.go
package leetcode func numberOfBoomerangs(points [][]int) int { res := 0 for i := 0; i < len(points); i++ { record := make(map[int]int, len(points)) for j := 0; j < len(points); j++ { if j != i { record[dis(points[i], points[j])]++ } } for _, r := range record { res += r * (r - 1) } } return ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0090.Subsets-II/90. Subsets II.go
leetcode/0090.Subsets-II/90. Subsets II.go
package leetcode import ( "fmt" "sort" ) func subsetsWithDup(nums []int) [][]int { c, res := []int{}, [][]int{} sort.Ints(nums) // 这里是去重的关键逻辑 for k := 0; k <= len(nums); k++ { generateSubsetsWithDup(nums, k, 0, c, &res) } return res } func generateSubsetsWithDup(nums []int, k, start int, c []int, res *[][]i...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0090.Subsets-II/90. Subsets II_test.go
leetcode/0090.Subsets-II/90. Subsets II_test.go
package leetcode import ( "fmt" "testing" ) type question90 struct { para90 ans90 } // para 是参数 // one 代表第一个参数 type para90 struct { one []int } // ans 是答案 // one 代表第一个答案 type ans90 struct { one [][]int } func Test_Problem90(t *testing.T) { qs := []question90{ { para90{[]int{}}, ans90{[][]int{{}}},...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1047.Remove-All-Adjacent-Duplicates-In-String/1047. Remove All Adjacent Duplicates In String_test.go
leetcode/1047.Remove-All-Adjacent-Duplicates-In-String/1047. Remove All Adjacent Duplicates In String_test.go
package leetcode import ( "fmt" "testing" ) type question1047 struct { para1047 ans1047 } // para 是参数 // one 代表第一个参数 type para1047 struct { s string } // ans 是答案 // one 代表第一个答案 type ans1047 struct { one string } func Test_Problem1047(t *testing.T) { qs := []question1047{ { para1047{"abbaca"}, ans1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1047.Remove-All-Adjacent-Duplicates-In-String/1047. Remove All Adjacent Duplicates In String.go
leetcode/1047.Remove-All-Adjacent-Duplicates-In-String/1047. Remove All Adjacent Duplicates In String.go
package leetcode func removeDuplicates1047(S string) string { stack := []rune{} for _, s := range S { if len(stack) == 0 || len(stack) > 0 && stack[len(stack)-1] != s { stack = append(stack, s) } else { stack = stack[:len(stack)-1] } } return string(stack) }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0924.Minimize-Malware-Spread/924. Minimize Malware Spread.go
leetcode/0924.Minimize-Malware-Spread/924. Minimize Malware Spread.go
package leetcode import ( "math" "github.com/halfrost/LeetCode-Go/template" ) func minMalwareSpread(graph [][]int, initial []int) int { if len(initial) == 0 { return 0 } uf, maxLen, maxIdx, uniqInitials, compMap := template.UnionFindCount{}, math.MinInt32, -1, map[int]int{}, map[int][]int{} uf.Init(len(graph...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0924.Minimize-Malware-Spread/924. Minimize Malware Spread_test.go
leetcode/0924.Minimize-Malware-Spread/924. Minimize Malware Spread_test.go
package leetcode import ( "fmt" "testing" ) type question924 struct { para924 ans924 } // para 是参数 // one 代表第一个参数 type para924 struct { graph [][]int initial []int } // ans 是答案 // one 代表第一个答案 type ans924 struct { one int } func Test_Problem924(t *testing.T) { qs := []question924{ { para924{[][]int...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0225.Implement-Stack-using-Queues/225. Implement Stack using Queues.go
leetcode/0225.Implement-Stack-using-Queues/225. Implement Stack using Queues.go
package leetcode type MyStack struct { enque []int deque []int } /** Initialize your data structure here. */ func Constructor225() MyStack { return MyStack{[]int{}, []int{}} } /** Push element x onto stack. */ func (this *MyStack) Push(x int) { this.enque = append(this.enque, x) } /** Removes the element on top...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0225.Implement-Stack-using-Queues/225. Implement Stack using Queues_test.go
leetcode/0225.Implement-Stack-using-Queues/225. Implement Stack using Queues_test.go
package leetcode import ( "fmt" "testing" ) func Test_Problem225(t *testing.T) { obj := Constructor225() fmt.Printf("obj = %v\n", obj) param5 := obj.Empty() fmt.Printf("param_5 = %v\n", param5) obj.Push(2) fmt.Printf("obj = %v\n", obj) obj.Push(10) fmt.Printf("obj = %v\n", obj) param2 := obj.Pop() fmt.Pri...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0551.Student-Attendance-Record-I/551.Student Attendance Record I.go
leetcode/0551.Student-Attendance-Record-I/551.Student Attendance Record I.go
package leetcode func checkRecord(s string) bool { numsA, maxL, numsL := 0, 0, 0 for _, v := range s { if v == 'L' { numsL++ } else { if numsL > maxL { maxL = numsL } numsL = 0 if v == 'A' { numsA++ } } } if numsL > maxL { maxL = numsL } return numsA < 2 && maxL < 3 }
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0551.Student-Attendance-Record-I/551.Student Attendance Record I_test.go
leetcode/0551.Student-Attendance-Record-I/551.Student Attendance Record I_test.go
package leetcode import ( "fmt" "testing" ) type question551 struct { para551 ans551 } // para 是参数 type para551 struct { s string } // ans 是答案 type ans551 struct { ans bool } func Test_Problem551(t *testing.T) { qs := []question551{ { para551{"PPALLP"}, ans551{true}, }, { para551{"PPALLL"}...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0504.Base-7/504.Base 7_test.go
leetcode/0504.Base-7/504.Base 7_test.go
package leetcode import ( "fmt" "testing" ) type question504 struct { para504 ans504 } // para 是参数 type para504 struct { num int } // ans 是答案 type ans504 struct { ans string } func Test_Problem504(t *testing.T) { qs := []question504{ { para504{100}, ans504{"202"}, }, { para504{-7}, ans5...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0504.Base-7/504.Base 7.go
leetcode/0504.Base-7/504.Base 7.go
package leetcode import "strconv" func convertToBase7(num int) string { if num == 0 { return "0" } negative := false if num < 0 { negative = true num = -num } var ans string var nums []int for num != 0 { remainder := num % 7 nums = append(nums, remainder) num = num / 7 } if negative { ans += "...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0791.Custom-Sort-String/791. Custom Sort String_test.go
leetcode/0791.Custom-Sort-String/791. Custom Sort String_test.go
package leetcode import ( "fmt" "testing" ) type question791 struct { para791 ans791 } // para 是参数 // one 代表第一个参数 type para791 struct { order string str string } // ans 是答案 // one 代表第一个答案 type ans791 struct { one string } func Test_Problem791(t *testing.T) { qs := []question791{ { para791{"cba", "...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0791.Custom-Sort-String/791. Custom Sort String.go
leetcode/0791.Custom-Sort-String/791. Custom Sort String.go
package leetcode import "sort" func customSortString(order string, str string) string { magic := map[byte]int{} for i := range order { magic[order[i]] = i - 30 } byteSlice := []byte(str) sort.Slice(byteSlice, func(i, j int) bool { return magic[byteSlice[i]] < magic[byteSlice[j]] }) return string(byteSlice)...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation.go
leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation.go
package leetcode func interpret(command string) string { if command == "" { return "" } res := "" for i := 0; i < len(command); i++ { if command[i] == 'G' { res += "G" } else { if command[i] == '(' && command[i+1] == 'a' { res += "al" i += 3 } else { res += "o" i++ } } } retur...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation_test.go
leetcode/1678.Goal-Parser-Interpretation/1678. Goal Parser Interpretation_test.go
package leetcode import ( "fmt" "testing" ) type question1678 struct { para1678 ans1678 } // para 是参数 // one 代表第一个参数 type para1678 struct { command string } // ans 是答案 // one 代表第一个答案 type ans1678 struct { one string } func Test_Problem1678(t *testing.T) { qs := []question1678{ { para1678{"G()(al)"}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close.go
leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close.go
package leetcode import ( "sort" ) func closeStrings(word1 string, word2 string) bool { if len(word1) != len(word2) { return false } freqCount1, freqCount2 := make([]int, 26), make([]int, 26) for _, c := range word1 { freqCount1[c-97]++ } for _, c := range word2 { freqCount2[c-97]++ } for i := 0; i < 2...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close_test.go
leetcode/1657.Determine-if-Two-Strings-Are-Close/1657. Determine if Two Strings Are Close_test.go
package leetcode import ( "fmt" "testing" ) type question1657 struct { para1657 ans1657 } // para 是参数 // one 代表第一个参数 type para1657 struct { word1 string word2 string } // ans 是答案 // one 代表第一个答案 type ans1657 struct { one bool } func Test_Problem1657(t *testing.T) { qs := []question1657{ { para1657{"a...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0892.Surface-Area-of-3D-Shapes/892. Surface Area of 3D Shapes.go
leetcode/0892.Surface-Area-of-3D-Shapes/892. Surface Area of 3D Shapes.go
package leetcode func surfaceArea(grid [][]int) int { area := 0 for i := 0; i < len(grid); i++ { for j := 0; j < len(grid[0]); j++ { if grid[i][j] == 0 { continue } area += grid[i][j]*4 + 2 // up if i > 0 { m := min(grid[i][j], grid[i-1][j]) area -= m } // down if i < len(grid)-...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0892.Surface-Area-of-3D-Shapes/892. Surface Area of 3D Shapes_test.go
leetcode/0892.Surface-Area-of-3D-Shapes/892. Surface Area of 3D Shapes_test.go
package leetcode import ( "fmt" "testing" ) type question892 struct { para892 ans892 } // para 是参数 // one 代表第一个参数 type para892 struct { one [][]int } // ans 是答案 // one 代表第一个答案 type ans892 struct { one int } func Test_Problem892(t *testing.T) { qs := []question892{ { para892{[][]int{{2}}}, ans892{1...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/Heap.go
structures/Heap.go
package structures // intHeap 实现了最小堆 heap 的接口 type intHeap []int func (h intHeap) Len() int { return len(h) } func (h intHeap) Less(i, j int) bool { return h[i] < h[j] } func (h intHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] } func (h *intHeap) Push(x interface{}) { // Push 使用 *h,是因为 // Push 增加了 h 的长度 *h ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/Stack_test.go
structures/Stack_test.go
package structures import ( "testing" "github.com/stretchr/testify/assert" ) func Test_Stack(t *testing.T) { ast := assert.New(t) s := NewStack() ast.True(s.IsEmpty(), "检查新建的 s 是否为空") start, end := 0, 100 for i := start; i < end; i++ { s.Push(i) ast.Equal(i-start+1, s.Len(), "Push 后检查 q 的长度。") } for...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/ListNode.go
structures/ListNode.go
package structures import ( "fmt" ) // ListNode 是链接节点 // 这个不能复制到*_test.go文件中。会导致Travis失败 type ListNode struct { Val int Next *ListNode } // List2Ints convert List to []int func List2Ints(head *ListNode) []int { // 链条深度限制,链条深度超出此限制,会 panic limit := 100 times := 0 res := []int{} for head != nil { times++ ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/Interval_test.go
structures/Interval_test.go
package structures import ( "testing" "github.com/stretchr/testify/assert" ) func Test_Interval2Ints(t *testing.T) { ast := assert.New(t) actual := Interval2Ints(Interval{Start: 1, End: 2}) expected := []int{1, 2} ast.Equal(expected, actual) } func Test_IntervalSlice2Intss(t *testing.T) { ast := assert.New(...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/Queue_test.go
structures/Queue_test.go
package structures import ( "testing" "github.com/stretchr/testify/assert" ) func Test_Queue(t *testing.T) { ast := assert.New(t) q := NewQueue() ast.True(q.IsEmpty(), "检查新建的 q 是否为空") start, end := 0, 100 for i := start; i < end; i++ { q.Push(i) ast.Equal(i-start+1, q.Len(), "Push 后检查 q 的长度。") } for...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/Interval.go
structures/Interval.go
package structures // Interval 提供区间表示 type Interval struct { Start int End int } // Interval2Ints 把 Interval 转换成 整型切片 func Interval2Ints(i Interval) []int { return []int{i.Start, i.End} } // IntervalSlice2Intss 把 []Interval 转换成 [][]int func IntervalSlice2Intss(is []Interval) [][]int { res := make([][]int, 0, l...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/ListNode_test.go
structures/ListNode_test.go
package structures import ( "testing" "github.com/stretchr/testify/assert" ) func Test_l2s(t *testing.T) { ast := assert.New(t) ast.Equal([]int{}, List2Ints(nil), "输入nil,没有返回[]int{}") one2three := &ListNode{ Val: 1, Next: &ListNode{ Val: 2, Next: &ListNode{ Val: 3, }, }, } ast.Equal([]int{...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/Point_test.go
structures/Point_test.go
package structures import ( "reflect" "testing" ) func Test_Intss2Points(t *testing.T) { type args struct { points [][]int } tests := []struct { name string args args want []Point }{ { "测试 [][]int 转换成 []Point ", args{ [][]int{ {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/Queue.go
structures/Queue.go
package structures // Queue 是用于存放 int 的队列 type Queue struct { nums []int } // NewQueue 返回 *kit.Queue func NewQueue() *Queue { return &Queue{nums: []int{}} } // Push 把 n 放入队列 func (q *Queue) Push(n int) { q.nums = append(q.nums, n) } // Pop 从 q 中取出最先进入队列的值 func (q *Queue) Pop() int { res := q.nums[0] q.nums = q...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/NestedInterger_test.go
structures/NestedInterger_test.go
package structures import ( "testing" "github.com/stretchr/testify/assert" ) func Test_NestedInteger(t *testing.T) { ast := assert.New(t) n := NestedInteger{} ast.True(n.IsInteger()) n.SetInteger(1) ast.Equal(1, n.GetInteger()) elem := NestedInteger{Num: 1} expected := NestedInteger{ Num: 1, Ns: [...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/Point.go
structures/Point.go
package structures // Point 定义了一个二维坐标点 type Point struct { X, Y int } // Intss2Points 把 [][]int 转换成 []Point func Intss2Points(points [][]int) []Point { res := make([]Point, len(points)) for i, p := range points { res[i] = Point{ X: p[0], Y: p[1], } } return res } // Points2Intss 把 []Point 转换成 [][]int ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false
halfrost/LeetCode-Go
https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/structures/TreeNode.go
structures/TreeNode.go
package structures import ( "fmt" "strconv" ) // TreeNode is tree's node type TreeNode struct { Val int Left *TreeNode Right *TreeNode } // NULL 方便添加测试数据 var NULL = -1 << 63 // Ints2TreeNode 利用 []int 生成 *TreeNode func Ints2TreeNode(ints []int) *TreeNode { n := len(ints) if n == 0 { return nil } root ...
go
MIT
d78a9e0927a302038992428433d2eb450efd93a2
2026-01-07T08:36:06.754118Z
false