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/0129.Sum-Root-to-Leaf-Numbers/129. Sum Root to Leaf Numbers_test.go | leetcode/0129.Sum-Root-to-Leaf-Numbers/129. Sum Root to Leaf Numbers_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question129 struct {
para129
ans129
}
// para 是参数
// one 代表第一个参数
type para129 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans129 struct {
one int
}
func Test_Problem129(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/0129.Sum-Root-to-Leaf-Numbers/129. Sum Root to Leaf Numbers.go | leetcode/0129.Sum-Root-to-Leaf-Numbers/129. Sum Root to Leaf Numbers.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 sumNumbers(root *TreeNode) int {
res := 0
d... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0201.Bitwise-AND-of-Numbers-Range/201. Bitwise AND of Numbers Range.go | leetcode/0201.Bitwise-AND-of-Numbers-Range/201. Bitwise AND of Numbers Range.go | package leetcode
// 解法一
func rangeBitwiseAnd1(m int, n int) int {
if m == 0 {
return 0
}
moved := 0
for m != n {
m >>= 1
n >>= 1
moved++
}
return m << uint32(moved)
}
// 解法二 Brian Kernighan's algorithm
func rangeBitwiseAnd(m int, n int) int {
for n > m {
n &= (n - 1) // 清除最低位的 1
}
return n
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0201.Bitwise-AND-of-Numbers-Range/201. Bitwise AND of Numbers Range_test.go | leetcode/0201.Bitwise-AND-of-Numbers-Range/201. Bitwise AND of Numbers Range_test.go | package leetcode
import (
"fmt"
"testing"
)
type question201 struct {
para201
ans201
}
// para 是参数
// one 代表第一个参数
type para201 struct {
m int
n int
}
// ans 是答案
// one 代表第一个答案
type ans201 struct {
one int
}
func Test_Problem201(t *testing.T) {
qs := []question201{
{
para201{5, 7},
ans201{4},
},... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1705.Maximum-Number-of-Eaten-Apples/1705.Maximum Number of Eaten Apples_test.go | leetcode/1705.Maximum-Number-of-Eaten-Apples/1705.Maximum Number of Eaten Apples_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1705 struct {
para1705
ans1705
}
// para 是参数
type para1705 struct {
apples []int
days []int
}
// ans 是答案
type ans1705 struct {
ans int
}
func Test_Problem1705(t *testing.T) {
qs := []question1705{
{
para1705{[]int{1, 2, 3, 5, 2}, []int{3, 2,... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1705.Maximum-Number-of-Eaten-Apples/1705.Maximum Number of Eaten Apples.go | leetcode/1705.Maximum-Number-of-Eaten-Apples/1705.Maximum Number of Eaten Apples.go | package leetcode
import "container/heap"
func eatenApples(apples []int, days []int) int {
h := hp{}
i := 0
var ans int
for ; i < len(apples); i++ {
for len(h) > 0 && h[0].end <= i {
heap.Pop(&h)
}
if apples[i] > 0 {
heap.Push(&h, data{apples[i], i + days[i]})
}
if len(h) > 0 {
minData := heap.P... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0890.Find-and-Replace-Pattern/890. Find and Replace Pattern.go | leetcode/0890.Find-and-Replace-Pattern/890. Find and Replace Pattern.go | package leetcode
func findAndReplacePattern(words []string, pattern string) []string {
res := make([]string, 0)
for _, word := range words {
if match(word, pattern) {
res = append(res, word)
}
}
return res
}
func match(w, p string) bool {
if len(w) != len(p) {
return false
}
m, used := make(map[uint8]... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0890.Find-and-Replace-Pattern/890. Find and Replace Pattern_test.go | leetcode/0890.Find-and-Replace-Pattern/890. Find and Replace Pattern_test.go | package leetcode
import (
"fmt"
"testing"
)
type question890 struct {
para890
ans890
}
// para 是参数
// one 代表第一个参数
type para890 struct {
words []string
pattern string
}
// ans 是答案
// one 代表第一个答案
type ans890 struct {
one []string
}
func Test_Problem890(t *testing.T) {
qs := []question890{
{
para890{... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0023.Merge-k-Sorted-Lists/23. Merge k Sorted Lists_test.go | leetcode/0023.Merge-k-Sorted-Lists/23. Merge k Sorted Lists_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question23 struct {
para23
ans23
}
// para 是参数
// one 代表第一个参数
type para23 struct {
one [][]int
}
// ans 是答案
// one 代表第一个答案
type ans23 struct {
one []int
}
func Test_Problem23(t *testing.T) {
qs := []question23{
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0023.Merge-k-Sorted-Lists/23. Merge k Sorted Lists.go | leetcode/0023.Merge-k-Sorted-Lists/23. Merge k Sorted Lists.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 mergeKLists(lists []*ListNode) *ListNode {
length := len(lists)
if ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home_test.go | leetcode/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1654 struct {
para1654
ans1654
}
// para 是参数
// one 代表第一个参数
type para1654 struct {
forbidden []int
a int
b int
x int
}
// ans 是答案
// one 代表第一个答案
type ans1654 struct {
one int
}
func Test_Problem1654(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/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home.go | leetcode/1654.Minimum-Jumps-to-Reach-Home/1654. Minimum Jumps to Reach Home.go | package leetcode
func minimumJumps(forbidden []int, a int, b int, x int) int {
visited := make([]bool, 6000)
for i := range forbidden {
visited[forbidden[i]] = true
}
queue, res := [][2]int{{0, 0}}, -1
for len(queue) > 0 {
length := len(queue)
res++
for i := 0; i < length; i++ {
cur, isBack := queue[i]... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array.go | leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array.go | package leetcode
// 解法一 超简洁写法
func waysToMakeFair(nums []int) int {
sum, res := [2]int{}, 0
for i := 0; i < len(nums); i++ {
sum[i%2] += nums[i]
}
for i := 0; i < len(nums); i++ {
sum[i%2] -= nums[i]
if sum[i%2] == sum[1-(i%2)] {
res++
}
sum[1-(i%2)] += nums[i]
}
return res
}
// 解法二 前缀和,后缀和
func wa... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array_test.go | leetcode/1664.Ways-to-Make-a-Fair-Array/1664. Ways to Make a Fair Array_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1664 struct {
para1664
ans1664
}
// para 是参数
// one 代表第一个参数
type para1664 struct {
nums []int
}
// ans 是答案
// one 代表第一个答案
type ans1664 struct {
one int
}
func Test_Problem1664(t *testing.T) {
qs := []question1664{
{
para1664{[]int{6, 1, 7, 4, 1... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0385.Mini-Parser/385. Mini Parser.go | leetcode/0385.Mini-Parser/385. Mini Parser.go | package leetcode
import (
"fmt"
"strconv"
)
/**
* // This is the interface that allows for creating nested lists.
* // You should not implement it, or speculate about its implementation
* type NestedInteger struct {
* }
*
* // Return true if this NestedInteger holds a single integer, rather than a nested list... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0385.Mini-Parser/385. Mini Parser_test.go | leetcode/0385.Mini-Parser/385. Mini Parser_test.go | package leetcode
import (
"fmt"
"testing"
)
type question385 struct {
para385
ans385
}
// para 是参数
// one 代表第一个参数
type para385 struct {
n string
}
// ans 是答案
// one 代表第一个答案
type ans385 struct {
one []int
}
func Test_Problem385(t *testing.T) {
qs := []question385{
{
para385{"[[]]"},
ans385{[]int{}}... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0563.Binary-Tree-Tilt/563. Binary Tree Tilt.go | leetcode/0563.Binary-Tree-Tilt/563. Binary Tree Tilt.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 findTilt(root *TreeNode) int {
if r... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0563.Binary-Tree-Tilt/563. Binary Tree Tilt_test.go | leetcode/0563.Binary-Tree-Tilt/563. Binary Tree Tilt_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question563 struct {
para563
ans563
}
// para 是参数
// one 代表第一个参数
type para563 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans563 struct {
one int
}
func Test_Problem563(t *testing.T) {
qs := []question56... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0576.Out-of-Boundary-Paths/576. Out of Boundary Paths_test.go | leetcode/0576.Out-of-Boundary-Paths/576. Out of Boundary Paths_test.go | package leetcode
import (
"fmt"
"testing"
)
type question576 struct {
para576
ans576
}
// para 是参数
// one 代表第一个参数
type para576 struct {
m int
n int
maxMove int
startRow int
startColumn int
}
// ans 是答案
// one 代表第一个答案
type ans576 struct {
one int
}
func Test_Problem576(t *testin... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0576.Out-of-Boundary-Paths/576. Out of Boundary Paths.go | leetcode/0576.Out-of-Boundary-Paths/576. Out of Boundary Paths.go | package leetcode
var dir = [][]int{
{-1, 0},
{0, 1},
{1, 0},
{0, -1},
}
func findPaths(m int, n int, maxMove int, startRow int, startColumn int) int {
visited := make([][][]int, m)
for i := range visited {
visited[i] = make([][]int, n)
for j := range visited[i] {
visited[i][j] = make([]int, maxMove+1)
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0480.Sliding-Window-Median/480. Sliding Window Median_test.go | leetcode/0480.Sliding-Window-Median/480. Sliding Window Median_test.go | package leetcode
import (
"fmt"
"testing"
)
type question480 struct {
para480
ans480
}
// para 是参数
// one 代表第一个参数
type para480 struct {
one []int
k int
}
// ans 是答案
// one 代表第一个答案
type ans480 struct {
one []int
}
func Test_Problem480(t *testing.T) {
qs := []question480{
{
para480{[]int{1, 3, -1, -... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0480.Sliding-Window-Median/480. Sliding Window Median.go | leetcode/0480.Sliding-Window-Median/480. Sliding Window Median.go | package leetcode
import (
"container/heap"
"container/list"
"sort"
)
// 解法一 用链表按照题意实现 时间复杂度 O(n * k) 空间复杂度 O(k)
func medianSlidingWindow(nums []int, k int) []float64 {
var res []float64
w := getWindowList(nums[:k], k)
res = append(res, getMedian(w, k))
for p1 := k; p1 < len(nums); p1++ {
w = removeFromWindo... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0721.Accounts-Merge/721. Accounts Merge.go | leetcode/0721.Accounts-Merge/721. Accounts Merge.go | package leetcode
import (
"sort"
"github.com/halfrost/LeetCode-Go/template"
)
// 解法一 并查集优化搜索解法
func accountsMerge(accounts [][]string) (r [][]string) {
uf := template.UnionFind{}
uf.Init(len(accounts))
// emailToID 将所有的 email 邮箱都拆开,拆开与 id(数组下标) 对应
// idToName 将 id(数组下标) 与 name 对应
// idToEmails 将 id(数组下标) 与整理好... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0721.Accounts-Merge/721. Accounts Merge_test.go | leetcode/0721.Accounts-Merge/721. Accounts Merge_test.go | package leetcode
import (
"fmt"
"testing"
)
type question721 struct {
para721
ans721
}
// para 是参数
// one 代表第一个参数
type para721 struct {
w [][]string
}
// ans 是答案
// one 代表第一个答案
type ans721 struct {
one [][]string
}
func Test_Problem721(t *testing.T) {
qs := []question721{
{
para721{[][]string{{"John"... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1572.Matrix-Diagonal-Sum/1572.Matrix Diagonal Sum_test.go | leetcode/1572.Matrix-Diagonal-Sum/1572.Matrix Diagonal Sum_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1572 struct {
para1572
ans1572
}
// para 是参数
type para1572 struct {
mat [][]int
}
// ans 是答案
// one 代表第一个答案
type ans1572 struct {
one int
}
func Test_Problem1572(t *testing.T) {
qs := []question1572{
{
para1572{[][]int{{1, 2, 3}, {4, 5, 6}, {7,... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1572.Matrix-Diagonal-Sum/1572.Matrix Diagonal Sum.go | leetcode/1572.Matrix-Diagonal-Sum/1572.Matrix Diagonal Sum.go | package leetcode
func diagonalSum(mat [][]int) int {
n := len(mat)
ans := 0
for pi := 0; pi < n; pi++ {
ans += mat[pi][pi]
}
for si, sj := n-1, 0; sj < n; si, sj = si-1, sj+1 {
ans += mat[si][sj]
}
if n%2 == 0 {
return ans
}
return ans - mat[n/2][n/2]
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1108.Defanging-an-IP-Address/1108. Defanging an IP Address.go | leetcode/1108.Defanging-an-IP-Address/1108. Defanging an IP Address.go | package leetcode
import "strings"
func defangIPaddr(address string) string {
return strings.Replace(address, ".", "[.]", -1)
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1108.Defanging-an-IP-Address/1108. Defanging an IP Address_test.go | leetcode/1108.Defanging-an-IP-Address/1108. Defanging an IP Address_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1108 struct {
para1108
ans1108
}
// para 是参数
// one 代表第一个参数
type para1108 struct {
one string
}
// ans 是答案
// one 代表第一个答案
type ans1108 struct {
one string
}
func Test_Problem1108(t *testing.T) {
qs := []question1108{
{
para1108{"1.1.1.1"},
a... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0676.Implement-Magic-Dictionary/676. Implement Magic Dictionary_test.go | leetcode/0676.Implement-Magic-Dictionary/676. Implement Magic Dictionary_test.go | package leetcode
import (
"fmt"
"testing"
)
func Test_Problem676(t *testing.T) {
dict := []string{"hello", "leetcode"}
obj := Constructor676()
obj.BuildDict(dict)
fmt.Printf("obj = %v\n", obj)
fmt.Println(obj.Search("hello"))
fmt.Println(obj.Search("apple"))
fmt.Println(obj.Search("leetcode"))
fmt.Println(o... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0676.Implement-Magic-Dictionary/676. Implement Magic Dictionary.go | leetcode/0676.Implement-Magic-Dictionary/676. Implement Magic Dictionary.go | package leetcode
type MagicDictionary struct {
rdict map[int]string
}
/** Initialize your data structure here. */
func Constructor676() MagicDictionary {
return MagicDictionary{rdict: make(map[int]string)}
}
/** Build a dictionary through a list of words */
func (this *MagicDictionary) BuildDict(dict []string) {
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue_test.go | leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue_test.go | package leetcode
import (
"fmt"
"testing"
)
func Test_Problem1670(t *testing.T) {
obj := Constructor()
fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
obj.PushFront(1)
fmt.Printf("obj = %v %v\n", MList2Ints(&obj), obj)
obj.PushBack(2)
fmt.Printf("obj = %v\n", MList2Ints(&obj))
obj.PushMiddle(3)
fmt.Print... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue.go | leetcode/1670.Design-Front-Middle-Back-Queue/1670. Design Front Middle Back Queue.go | package leetcode
import (
"container/list"
)
type FrontMiddleBackQueue struct {
list *list.List
middle *list.Element
}
func Constructor() FrontMiddleBackQueue {
return FrontMiddleBackQueue{list: list.New()}
}
func (this *FrontMiddleBackQueue) PushFront(val int) {
e := this.list.PushFront(val)
if this.middle... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0203.Remove-Linked-List-Elements/203. Remove Linked List Elements_test.go | leetcode/0203.Remove-Linked-List-Elements/203. Remove Linked List Elements_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question203 struct {
para203
ans203
}
// para 是参数
// one 代表第一个参数
type para203 struct {
one []int
n int
}
// ans 是答案
// one 代表第一个答案
type ans203 struct {
one []int
}
func Test_Problem203(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/0203.Remove-Linked-List-Elements/203. Remove Linked List Elements.go | leetcode/0203.Remove-Linked-List-Elements/203. Remove Linked List Elements.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 removeElements(head *ListNode, val int) *ListNode {
if head == nil {... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1038.Binary-Search-Tree-to-Greater-Sum-Tree/1038. Binary Search Tree to Greater Sum Tree.go | leetcode/1038.Binary-Search-Tree-to-Greater-Sum-Tree/1038. Binary Search Tree to Greater Sum 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 bstToGst(root *TreeNode) *TreeNode {
if root... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1038.Binary-Search-Tree-to-Greater-Sum-Tree/1038. Binary Search Tree to Greater Sum Tree_test.go | leetcode/1038.Binary-Search-Tree-to-Greater-Sum-Tree/1038. Binary Search Tree to Greater Sum Tree_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question1038 struct {
para1038
ans1038
}
// para 是参数
// one 代表第一个参数
type para1038 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans1038 struct {
one []int
}
func Test_Problem1038(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/0401.Binary-Watch/401. Binary Watch_test.go | leetcode/0401.Binary-Watch/401. Binary Watch_test.go | package leetcode
import (
"fmt"
"testing"
)
type question401 struct {
para401
ans401
}
// para 是参数
// one 代表第一个参数
type para401 struct {
n int
}
// ans 是答案
// one 代表第一个答案
type ans401 struct {
one []string
}
func Test_Problem401(t *testing.T) {
qs := []question401{
{
para401{1},
ans401{[]string{"1:0... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0401.Binary-Watch/401. Binary Watch.go | leetcode/0401.Binary-Watch/401. Binary Watch.go | package leetcode
import (
"fmt"
"strconv"
)
// 解法一
func readBinaryWatch(num int) []string {
memo := make([]int, 60)
// count the number of 1 in a binary number
count := func(n int) int {
if memo[n] != 0 {
return memo[n]
}
originN, res := n, 0
for n != 0 {
n = n & (n - 1)
res++
}
memo[originN... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0537.Complex-Number-Multiplication/537. Complex Number Multiplication_test.go | leetcode/0537.Complex-Number-Multiplication/537. Complex Number Multiplication_test.go | package leetcode
import (
"fmt"
"testing"
)
type question537 struct {
para537
ans537
}
// para 是参数
// one 代表第一个参数
type para537 struct {
a string
b string
}
// ans 是答案
// one 代表第一个答案
type ans537 struct {
one string
}
func Test_Problem537(t *testing.T) {
qs := []question537{
{
para537{"1+1i", "1+1i"},... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0537.Complex-Number-Multiplication/537. Complex Number Multiplication.go | leetcode/0537.Complex-Number-Multiplication/537. Complex Number Multiplication.go | package leetcode
import (
"strconv"
"strings"
)
func complexNumberMultiply(a string, b string) string {
realA, imagA := parse(a)
realB, imagB := parse(b)
real := realA*realB - imagA*imagB
imag := realA*imagB + realB*imagA
return strconv.Itoa(real) + "+" + strconv.Itoa(imag) + "i"
}
func parse(s string) (int, ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1048.Longest-String-Chain/1048. Longest String Chain_test.go | leetcode/1048.Longest-String-Chain/1048. Longest String Chain_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1048 struct {
para1048
ans1048
}
// para 是参数
// one 代表第一个参数
type para1048 struct {
words []string
}
// ans 是答案
// one 代表第一个答案
type ans1048 struct {
one int
}
func Test_Problem1048(t *testing.T) {
qs := []question1048{
{
para1048{[]string{"a", "... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1048.Longest-String-Chain/1048. Longest String Chain.go | leetcode/1048.Longest-String-Chain/1048. Longest String Chain.go | package leetcode
import "sort"
func longestStrChain(words []string) int {
sort.Slice(words, func(i, j int) bool { return len(words[i]) < len(words[j]) })
poss, res := make([]int, 16+2), 0
for i, w := range words {
if poss[len(w)] == 0 {
poss[len(w)] = i
}
}
dp := make([]int, len(words))
for i := len(word... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1157.Online-Majority-Element-In-Subarray/1157. Online Majority Element In Subarray.go | leetcode/1157.Online-Majority-Element-In-Subarray/1157. Online Majority Element In Subarray.go | package leetcode
import (
"sort"
)
type segmentItem struct {
candidate int
count int
}
// MajorityChecker define
type MajorityChecker struct {
segmentTree []segmentItem
data []int
merge func(i, j segmentItem) segmentItem
count map[int][]int
}
// Constructor1157 define
func Constructor1... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1157.Online-Majority-Element-In-Subarray/1157. Online Majority Element In Subarray_test.go | leetcode/1157.Online-Majority-Element-In-Subarray/1157. Online Majority Element In Subarray_test.go | package leetcode
import (
"fmt"
"testing"
)
func Test_Problem1157(t *testing.T) {
arr := []int{1, 1, 2, 2, 1, 1}
obj := Constructor1157(arr)
fmt.Printf("obj = %v\n", obj)
fmt.Printf("query(0,5,4) = %v\n", obj.Query(0, 5, 4)) //1
fmt.Printf("query(0,3,3) = %v\n", obj.Query(0, 3, 3)) //-1
fmt.Printf("query(2,3,... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1025.Divisor-Game/1025. Divisor Game.go | leetcode/1025.Divisor-Game/1025. Divisor Game.go | package leetcode
func divisorGame(N int) bool {
return N%2 == 0
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1025.Divisor-Game/1025. Divisor Game_test.go | leetcode/1025.Divisor-Game/1025. Divisor Game_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1025 struct {
para1025
ans1025
}
// para 是参数
// one 代表第一个参数
type para1025 struct {
one int
}
// ans 是答案
// one 代表第一个答案
type ans1025 struct {
one bool
}
func Test_Problem1025(t *testing.T) {
qs := []question1025{
{
para1025{2},
ans1025{true},
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1423.Maximum-Points-You-Can-Obtain-from-Cards/1423. Maximum Points You Can Obtain from Cards.go | leetcode/1423.Maximum-Points-You-Can-Obtain-from-Cards/1423. Maximum Points You Can Obtain from Cards.go | package leetcode
func maxScore(cardPoints []int, k int) int {
windowSize, sum := len(cardPoints)-k, 0
for _, val := range cardPoints[:windowSize] {
sum += val
}
minSum := sum
for i := windowSize; i < len(cardPoints); i++ {
sum += cardPoints[i] - cardPoints[i-windowSize]
if sum < minSum {
minSum = sum
}... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1423.Maximum-Points-You-Can-Obtain-from-Cards/1423. Maximum Points You Can Obtain from Cards_test.go | leetcode/1423.Maximum-Points-You-Can-Obtain-from-Cards/1423. Maximum Points You Can Obtain from Cards_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1423 struct {
para1423
ans1423
}
// para 是参数
// one 代表第一个参数
type para1423 struct {
cardPoints []int
k int
}
// ans 是答案
// one 代表第一个答案
type ans1423 struct {
one int
}
func Test_Problem1423(t *testing.T) {
qs := []question1423{
{
para14... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0213.House-Robber-II/213. House Robber II_test.go | leetcode/0213.House-Robber-II/213. House Robber II_test.go | package leetcode
import (
"fmt"
"testing"
)
type question213 struct {
para213
ans213
}
// para 是参数
// one 代表第一个参数
type para213 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans213 struct {
one int
}
func Test_Problem213(t *testing.T) {
qs := []question213{
{
para213{[]int{0, 0}},
ans213{0},
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0213.House-Robber-II/213. House Robber II.go | leetcode/0213.House-Robber-II/213. House Robber II.go | package leetcode
func rob213(nums []int) int {
n := len(nums)
if n == 0 {
return 0
}
if n == 1 {
return nums[0]
}
if n == 2 {
return max(nums[0], nums[1])
}
// 由于首尾是相邻的,所以需要对比 [0,n-1]、[1,n] 这两个区间的最大值
return max(rob213_1(nums, 0, n-2), rob213_1(nums, 1, n-1))
}
func rob213_1(nums []int, start, end int) ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2096.Step-By-Step-Directions-From-a-Binary-Tree-Node-to-Another/2096. Step-By-Step Directions From a Binary Tree Node to Another_test.go | leetcode/2096.Step-By-Step-Directions-From-a-Binary-Tree-Node-to-Another/2096. Step-By-Step Directions From a Binary Tree Node to Another_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question2096 struct {
para2096
ans2096
}
// para 是参数
// one 代表第一个参数
type para2096 struct {
one []int
startValue int
destValue int
}
// ans 是答案
// one 代表第一个答案
type ans2096 struct {
one string
}
func Test_... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2096.Step-By-Step-Directions-From-a-Binary-Tree-Node-to-Another/2096. Step-By-Step Directions From a Binary Tree Node to Another.go | leetcode/2096.Step-By-Step-Directions-From-a-Binary-Tree-Node-to-Another/2096. Step-By-Step Directions From a Binary Tree Node to Another.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 getDirections(root *TreeNode, startValue int,... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0343.Integer-Break/343. Integer Break.go | leetcode/0343.Integer-Break/343. Integer Break.go | package leetcode
func integerBreak(n int) int {
dp := make([]int, n+1)
dp[0], dp[1] = 1, 1
for i := 1; i <= n; i++ {
for j := 1; j < i; j++ {
// dp[i] = max(dp[i], j * (i - j), j*dp[i-j])
dp[i] = max(dp[i], j*max(dp[i-j], i-j))
}
}
return dp[n]
}
func max(a int, b int) int {
if a > b {
return a
}
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0343.Integer-Break/343. Integer Break_test.go | leetcode/0343.Integer-Break/343. Integer Break_test.go | package leetcode
import (
"fmt"
"testing"
)
type question343 struct {
para343
ans343
}
// para 是参数
// one 代表第一个参数
type para343 struct {
one int
}
// ans 是答案
// one 代表第一个答案
type ans343 struct {
one int
}
func Test_Problem343(t *testing.T) {
qs := []question343{
{
para343{2},
ans343{1},
},
{
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1304.Find-N-Unique-Integers-Sum-up-to-Zero/1304. Find N Unique Integers Sum up to Zero_test.go | leetcode/1304.Find-N-Unique-Integers-Sum-up-to-Zero/1304. Find N Unique Integers Sum up to Zero_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1304 struct {
para1304
ans1304
}
// para 是参数
// one 代表第一个参数
type para1304 struct {
one int
}
// ans 是答案
// one 代表第一个答案
type ans1304 struct {
one []int
}
func Test_Problem1304(t *testing.T) {
qs := []question1304{
{
para1304{5},
ans1304{[]int... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1304.Find-N-Unique-Integers-Sum-up-to-Zero/1304. Find N Unique Integers Sum up to Zero.go | leetcode/1304.Find-N-Unique-Integers-Sum-up-to-Zero/1304. Find N Unique Integers Sum up to Zero.go | package leetcode
func sumZero(n int) []int {
res, left, right, start := make([]int, n), 0, n-1, 1
for left < right {
res[left] = start
res[right] = -start
start++
left = left + 1
right = right - 1
}
return res
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0437.Path-Sum-III/437. Path Sum III_test.go | leetcode/0437.Path-Sum-III/437. Path Sum III_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question437 struct {
para437
ans437
}
// para 是参数
// one 代表第一个参数
type para437 struct {
one []int
sum int
}
// ans 是答案
// one 代表第一个答案
type ans437 struct {
one int
}
func Test_Problem437(t *testing.T) {
qs := []q... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0437.Path-Sum-III/437. Path Sum III.go | leetcode/0437.Path-Sum-III/437. Path Sum 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
* }
*/
// 解法一 带缓存 dfs
func pathSum(root *TreeNode, target... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2183.Count-Array-Pairs-Divisible-by-K/2183. Count Array Pairs Divisible by K.go | leetcode/2183.Count-Array-Pairs-Divisible-by-K/2183. Count Array Pairs Divisible by K.go | package leetcode
import "math"
func countPairs(nums []int, k int) int64 {
n := int(math.Sqrt(float64(k)))
gcds, res := make(map[int]int, n), 0
for _, num := range nums {
gcds[gcd(num, k)]++
}
for a, n1 := range gcds {
for b, n2 := range gcds {
if a > b || (a*b)%k != 0 {
continue
}
if a != b {
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2183.Count-Array-Pairs-Divisible-by-K/2183. Count Array Pairs Divisible by K_test.go | leetcode/2183.Count-Array-Pairs-Divisible-by-K/2183. Count Array Pairs Divisible by K_test.go | package leetcode
import (
"fmt"
"testing"
)
type question2182 struct {
para2182
ans2182
}
// para 是参数
// one 代表第一个参数
type para2182 struct {
nums []int
k int
}
// ans 是答案
// one 代表第一个答案
type ans2182 struct {
one int64
}
func Test_Problem2182(t *testing.T) {
qs := []question2182{
{
para2182{[]int{1... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0169.Majority-Element/169. Majority Element.go | leetcode/0169.Majority-Element/169. Majority Element.go | package leetcode
// 解法一 时间复杂度 O(n) 空间复杂度 O(1)
func majorityElement(nums []int) int {
res, count := nums[0], 0
for i := 0; i < len(nums); i++ {
if count == 0 {
res, count = nums[i], 1
} else {
if nums[i] == res {
count++
} else {
count--
}
}
}
return res
}
// 解法二 时间复杂度 O(n) 空间复杂度 O(n)
fun... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0169.Majority-Element/169. Majority Element_test.go | leetcode/0169.Majority-Element/169. Majority Element_test.go | package leetcode
import (
"fmt"
"testing"
)
type question169 struct {
para169
ans169
}
// para 是参数
// one 代表第一个参数
type para169 struct {
s []int
}
// ans 是答案
// one 代表第一个答案
type ans169 struct {
one int
}
func Test_Problem169(t *testing.T) {
qs := []question169{
{
para169{[]int{2, 2, 1}},
ans169{2},... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0218.The-Skyline-Problem/218. The Skyline Problem_test.go | leetcode/0218.The-Skyline-Problem/218. The Skyline Problem_test.go | package leetcode
import (
"fmt"
"testing"
)
type question218 struct {
para218
ans218
}
// para 是参数
// one 代表第一个参数
type para218 struct {
one [][]int
}
// ans 是答案
// one 代表第一个答案
type ans218 struct {
one [][]int
}
func Test_Problem218(t *testing.T) {
qs := []question218{
{
para218{[][]int{{2, 9, 10}, {3... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0218.The-Skyline-Problem/218. The Skyline Problem.go | leetcode/0218.The-Skyline-Problem/218. The Skyline Problem.go | package leetcode
import (
"sort"
"github.com/halfrost/LeetCode-Go/template"
)
// 解法一 树状数组,时间复杂度 O(n log n)
const LEFTSIDE = 1
const RIGHTSIDE = 2
type Point struct {
xAxis int
side int
index int
}
func getSkyline(buildings [][]int) [][]int {
res := [][]int{}
if len(buildings) == 0 {
return res
}
allPoi... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0017.Letter-Combinations-of-a-Phone-Number/17. Letter Combinations of a Phone Number_test.go | leetcode/0017.Letter-Combinations-of-a-Phone-Number/17. Letter Combinations of a Phone Number_test.go | package leetcode
import (
"fmt"
"testing"
)
type question17 struct {
para17
ans17
}
// para 是参数
// one 代表第一个参数
type para17 struct {
s string
}
// ans 是答案
// one 代表第一个答案
type ans17 struct {
one []string
}
func Test_Problem17(t *testing.T) {
qs := []question17{
{
para17{"23"},
ans17{[]string{"ad", "... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0017.Letter-Combinations-of-a-Phone-Number/17. Letter Combinations of a Phone Number.go | leetcode/0017.Letter-Combinations-of-a-Phone-Number/17. Letter Combinations of a Phone Number.go | package leetcode
var (
letterMap = []string{
" ", //0
"", //1
"abc", //2
"def", //3
"ghi", //4
"jkl", //5
"mno", //6
"pqrs", //7
"tuv", //8
"wxyz", //9
}
res = []string{}
final = 0
)
// 解法一 DFS
func letterCombinations(digits string) []string {
if digits == "" {
return []strin... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced_test.go | leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1653 struct {
para1653
ans1653
}
// para 是参数
// one 代表第一个参数
type para1653 struct {
s string
}
// ans 是答案
// one 代表第一个答案
type ans1653 struct {
one int
}
func Test_Problem1653(t *testing.T) {
qs := []question1653{
{
para1653{"aababbab"},
ans16... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced.go | leetcode/1653.Minimum-Deletions-to-Make-String-Balanced/1653. Minimum Deletions to Make String Balanced.go | package leetcode
// 解法一 DP
func minimumDeletions(s string) int {
prev, res, bCount := 0, 0, 0
for _, c := range s {
if c == 'a' {
res = min(prev+1, bCount)
prev = res
} else {
bCount++
}
}
return res
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
// 解法二 模拟
func minimumDeletions1(... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0290.Word-Pattern/290. Word Pattern.go | leetcode/0290.Word-Pattern/290. Word Pattern.go | package leetcode
import "strings"
func wordPattern(pattern string, str string) bool {
strList := strings.Split(str, " ")
patternByte := []byte(pattern)
if pattern == "" || len(patternByte) != len(strList) {
return false
}
pMap := map[byte]string{}
sMap := map[string]byte{}
for index, b := range patternByte ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0290.Word-Pattern/290. Word Pattern_test.go | leetcode/0290.Word-Pattern/290. Word Pattern_test.go | package leetcode
import (
"fmt"
"testing"
)
type question290 struct {
para290
ans290
}
// para 是参数
// one 代表第一个参数
type para290 struct {
one string
two string
}
// ans 是答案
// one 代表第一个答案
type ans290 struct {
one bool
}
func Test_Problem290(t *testing.T) {
qs := []question290{
{
para290{"abba", "dog c... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0392.Is-Subsequence/392. Is Subsequence.go | leetcode/0392.Is-Subsequence/392. Is Subsequence.go | package leetcode
// 解法一 O(n^2)
func isSubsequence(s string, t string) bool {
index := 0
for i := 0; i < len(s); i++ {
flag := false
for ; index < len(t); index++ {
if s[i] == t[index] {
flag = true
break
}
}
if flag == true {
index++
continue
} else {
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/0392.Is-Subsequence/392. Is Subsequence_test.go | leetcode/0392.Is-Subsequence/392. Is Subsequence_test.go | package leetcode
import (
"fmt"
"testing"
)
type question392 struct {
para392
ans392
}
// para 是参数
// one 代表第一个参数
type para392 struct {
one string
two string
}
// ans 是答案
// one 代表第一个答案
type ans392 struct {
one bool
}
func Test_Problem392(t *testing.T) {
qs := []question392{
{
para392{"abc", "ahbgdc... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0390.Elimination-Game/390. Elimination Game_test.go | leetcode/0390.Elimination-Game/390. Elimination Game_test.go | package leetcode
import (
"fmt"
"testing"
)
type question390 struct {
para390
ans390
}
// para 是参数
// one 代表第一个参数
type para390 struct {
n int
}
// ans 是答案
// one 代表第一个答案
type ans390 struct {
one int
}
func Test_Problem390(t *testing.T) {
qs := []question390{
{
para390{9},
ans390{6},
},
{
p... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0390.Elimination-Game/390. Elimination Game.go | leetcode/0390.Elimination-Game/390. Elimination Game.go | package leetcode
func lastRemaining(n int) int {
start, dir, step := 1, true, 1
for n > 1 {
if dir { // 正向
start += step
} else { // 反向
if n%2 == 1 {
start += step
}
}
dir = !dir
n >>= 1
step <<= 1
}
return start
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0341.Flatten-Nested-List-Iterator/341. Flatten Nested List Iterator.go | leetcode/0341.Flatten-Nested-List-Iterator/341. Flatten Nested List Iterator.go | package leetcode
import "container/list"
// This is the interface that allows for creating nested lists.
// You should not implement it, or speculate about its implementation
type NestedInteger struct {
}
// Return true if this NestedInteger holds a single integer, rather than a nested list.
func (this NestedInteger... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0341.Flatten-Nested-List-Iterator/341. Flatten Nested List Iterator_test.go | leetcode/0341.Flatten-Nested-List-Iterator/341. Flatten Nested List Iterator_test.go | package leetcode
import (
"fmt"
"testing"
)
func Test_Problem338(t *testing.T) {
obj := Constructor([]*NestedInteger{})
fmt.Printf("obj = %v\n", obj)
fmt.Printf("obj = %v\n", obj.Next())
fmt.Printf("obj = %v\n", obj.HasNext())
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1742.Maximum-Number-of-Balls-in-a-Box/1742. Maximum Number of Balls in a Box.go | leetcode/1742.Maximum-Number-of-Balls-in-a-Box/1742. Maximum Number of Balls in a Box.go | package leetcode
func countBalls(lowLimit int, highLimit int) int {
buckets, maxBall := [46]int{}, 0
for i := lowLimit; i <= highLimit; i++ {
t := 0
for j := i; j > 0; {
t += j % 10
j = j / 10
}
buckets[t]++
if buckets[t] > maxBall {
maxBall = buckets[t]
}
}
return maxBall
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1742.Maximum-Number-of-Balls-in-a-Box/1742. Maximum Number of Balls in a Box_test.go | leetcode/1742.Maximum-Number-of-Balls-in-a-Box/1742. Maximum Number of Balls in a Box_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1742 struct {
para1742
ans1742
}
// para 是参数
// one 代表第一个参数
type para1742 struct {
lowLimit int
highLimit int
}
// ans 是答案
// one 代表第一个答案
type ans1742 struct {
one int
}
func Test_Problem1742(t *testing.T) {
qs := []question1742{
{
para1742{1... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers/1317. Convert Integer to the Sum of Two No-Zero Integers_test.go | leetcode/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers/1317. Convert Integer to the Sum of Two No-Zero Integers_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1317 struct {
para1317
ans1317
}
// para 是参数
// one 代表第一个参数
type para1317 struct {
one int
}
// ans 是答案
// one 代表第一个答案
type ans1317 struct {
one []int
}
func Test_Problem1317(t *testing.T) {
qs := []question1317{
{
para1317{5},
ans1317{[]int... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers/1317. Convert Integer to the Sum of Two No-Zero Integers.go | leetcode/1317.Convert-Integer-to-the-Sum-of-Two-No-Zero-Integers/1317. Convert Integer to the Sum of Two No-Zero Integers.go | package leetcode
func getNoZeroIntegers(n int) []int {
noZeroPair := []int{}
for i := 1; i <= n/2; i++ {
if isNoZero(i) && isNoZero(n-i) {
noZeroPair = append(noZeroPair, []int{i, n - i}...)
break
}
}
return noZeroPair
}
func isNoZero(n int) bool {
for n != 0 {
if n%10 == 0 {
return false
}
n ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0674.Longest-Continuous-Increasing-Subsequence/674. Longest Continuous Increasing Subsequence.go | leetcode/0674.Longest-Continuous-Increasing-Subsequence/674. Longest Continuous Increasing Subsequence.go | package leetcode
func findLengthOfLCIS(nums []int) int {
if len(nums) == 0 {
return 0
}
res, length := 1, 1
for i := 1; i < len(nums); i++ {
if nums[i] > nums[i-1] {
length++
} else {
res = max(res, length)
length = 1
}
}
return max(res, length)
}
func max(a, b int) int {
if a > b {
return a... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0674.Longest-Continuous-Increasing-Subsequence/674. Longest Continuous Increasing Subsequence_test.go | leetcode/0674.Longest-Continuous-Increasing-Subsequence/674. Longest Continuous Increasing Subsequence_test.go | package leetcode
import (
"fmt"
"testing"
)
type question674 struct {
para674
ans674
}
// para 是参数
// one 代表第一个参数
type para674 struct {
nums []int
}
// ans 是答案
// one 代表第一个答案
type ans674 struct {
one int
}
func Test_Problem674(t *testing.T) {
qs := []question674{
{
para674{[]int{1, 3, 5, 4, 7}},
a... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0961.N-Repeated-Element-in-Size-2N-Array/961. N-Repeated Element in Size 2N Array.go | leetcode/0961.N-Repeated-Element-in-Size-2N-Array/961. N-Repeated Element in Size 2N Array.go | package leetcode
func repeatedNTimes(A []int) int {
kv := make(map[int]struct{})
for _, val := range A {
if _, ok := kv[val]; ok {
return val
}
kv[val] = struct{}{}
}
return 0
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0961.N-Repeated-Element-in-Size-2N-Array/961. N-Repeated Element in Size 2N Array_test.go | leetcode/0961.N-Repeated-Element-in-Size-2N-Array/961. N-Repeated Element in Size 2N Array_test.go | package leetcode
import (
"fmt"
"testing"
)
type question961 struct {
para961
ans961
}
// para 是参数
// one 代表第一个参数
type para961 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans961 struct {
one int
}
func Test_Problem961(t *testing.T) {
qs := []question961{
{
para961{[]int{1, 2, 3, 3}},
ans961... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1734.Decode-XORed-Permutation/1734. Decode XORed Permutation_test.go | leetcode/1734.Decode-XORed-Permutation/1734. Decode XORed Permutation_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1734 struct {
para1734
ans1734
}
// para 是参数
// one 代表第一个参数
type para1734 struct {
encoded []int
}
// ans 是答案
// one 代表第一个答案
type ans1734 struct {
one []int
}
func Test_Problem1734(t *testing.T) {
qs := []question1734{
{
para1734{[]int{3, 1}},
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1734.Decode-XORed-Permutation/1734. Decode XORed Permutation.go | leetcode/1734.Decode-XORed-Permutation/1734. Decode XORed Permutation.go | package leetcode
func decode(encoded []int) []int {
n, total, odd := len(encoded), 0, 0
for i := 1; i <= n+1; i++ {
total ^= i
}
for i := 1; i < n; i += 2 {
odd ^= encoded[i]
}
perm := make([]int, n+1)
perm[0] = total ^ odd
for i, v := range encoded {
perm[i+1] = perm[i] ^ v
}
return perm
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1482.Minimum-Number-of-Days-to-Make-m-Bouquets/1482. Minimum Number of Days to Make m Bouquets_test.go | leetcode/1482.Minimum-Number-of-Days-to-Make-m-Bouquets/1482. Minimum Number of Days to Make m Bouquets_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1482 struct {
para1482
ans1482
}
// para 是参数
// one 代表第一个参数
type para1482 struct {
bloomDay []int
m int
k int
}
// ans 是答案
// one 代表第一个答案
type ans1482 struct {
one int
}
func Test_Problem1482(t *testing.T) {
qs := []question1482{
{... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1482.Minimum-Number-of-Days-to-Make-m-Bouquets/1482. Minimum Number of Days to Make m Bouquets.go | leetcode/1482.Minimum-Number-of-Days-to-Make-m-Bouquets/1482. Minimum Number of Days to Make m Bouquets.go | package leetcode
import "sort"
func minDays(bloomDay []int, m int, k int) int {
if m*k > len(bloomDay) {
return -1
}
maxDay := 0
for _, day := range bloomDay {
if day > maxDay {
maxDay = day
}
}
return sort.Search(maxDay, func(days int) bool {
flowers, bouquets := 0, 0
for _, d := range bloomDay {
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1022.Sum-of-Root-To-Leaf-Binary-Numbers/1022. Sum of Root To Leaf Binary Numbers.go | leetcode/1022.Sum-of-Root-To-Leaf-Binary-Numbers/1022. Sum of Root To Leaf Binary Numbers.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 sumRootToLeaf(root *TreeNode) int {
var dfs func(*... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1022.Sum-of-Root-To-Leaf-Binary-Numbers/1022. Sum of Root To Leaf Binary Numbers_test.go | leetcode/1022.Sum-of-Root-To-Leaf-Binary-Numbers/1022. Sum of Root To Leaf Binary Numbers_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question1022 struct {
para1022
ans1022
}
// para 是参数
// one 代表第一个参数
type para1022 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans1022 struct {
one int
}
func Test_Problem1022(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/0237.Delete-Node-in-a-Linked-List/237. Delete Node in a Linked List_test.go | leetcode/0237.Delete-Node-in-a-Linked-List/237. Delete Node in a Linked List_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question237 struct {
para237
ans237
}
// para 是参数
// one 代表第一个参数
type para237 struct {
one []int
n int
}
// ans 是答案
// one 代表第一个答案
type ans237 struct {
one []int
}
func Test_Problem237(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/0237.Delete-Node-in-a-Linked-List/237. Delete Node in a Linked List.go | leetcode/0237.Delete-Node-in-a-Linked-List/237. Delete Node in a 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 deleteNode(node *ListNode) {
node.Val = node.Next.Val
node.Next = n... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0647.Palindromic-Substrings/647. Palindromic Substrings_test.go | leetcode/0647.Palindromic-Substrings/647. Palindromic Substrings_test.go | package leetcode
import (
"fmt"
"testing"
)
type question647 struct {
para647
ans647
}
// para 是参数
// one 代表第一个参数
type para647 struct {
s string
}
// ans 是答案
// one 代表第一个答案
type ans647 struct {
one int
}
func Test_Problem647(t *testing.T) {
qs := []question647{
{
para647{"abc"},
ans647{3},
},
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0647.Palindromic-Substrings/647. Palindromic Substrings.go | leetcode/0647.Palindromic-Substrings/647. Palindromic Substrings.go | package leetcode
func countSubstrings(s string) int {
res := 0
for i := 0; i < len(s); i++ {
res += countPalindrome(s, i, i)
res += countPalindrome(s, i, i+1)
}
return res
}
func countPalindrome(s string, left, right int) int {
res := 0
for left >= 0 && right < len(s) {
if s[left] != s[right] {
break
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1026.Maximum-Difference-Between-Node-and-Ancestor/1026. Maximum Difference Between Node and Ancestor.go | leetcode/1026.Maximum-Difference-Between-Node-and-Ancestor/1026. Maximum Difference Between Node and Ancestor.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 maxAncestorDiff(root *TreeNode) int {
res := ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1026.Maximum-Difference-Between-Node-and-Ancestor/1026. Maximum Difference Between Node and Ancestor_test.go | leetcode/1026.Maximum-Difference-Between-Node-and-Ancestor/1026. Maximum Difference Between Node and Ancestor_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question1026 struct {
para1026
ans1026
}
// para 是参数
// one 代表第一个参数
type para1026 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans1026 struct {
one int
}
func Test_Problem1026(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/0322.Coin-Change/322. Coin Change_test.go | leetcode/0322.Coin-Change/322. Coin Change_test.go | package leetcode
import (
"fmt"
"testing"
)
type question322 struct {
para322
ans322
}
// para 是参数
// one 代表第一个参数
type para322 struct {
one []int
amount int
}
// ans 是答案
// one 代表第一个答案
type ans322 struct {
one int
}
func Test_Problem322(t *testing.T) {
qs := []question322{
{
para322{[]int{186, 41... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0322.Coin-Change/322. Coin Change.go | leetcode/0322.Coin-Change/322. Coin Change.go | package leetcode
func coinChange(coins []int, amount int) int {
dp := make([]int, amount+1)
dp[0] = 0
for i := 1; i < len(dp); i++ {
dp[i] = amount + 1
}
for i := 1; i <= amount; i++ {
for j := 0; j < len(coins); j++ {
if coins[j] <= i {
dp[i] = min(dp[i], dp[i-coins[j]]+1)
}
}
}
if dp[amount] >... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0118.Pascals-Triangle/118. Pascals Triangle_test.go | leetcode/0118.Pascals-Triangle/118. Pascals Triangle_test.go | package leetcode
import (
"fmt"
"testing"
)
type question118 struct {
para118
ans118
}
// para 是参数
// one 代表第一个参数
type para118 struct {
numRows int
}
// ans 是答案
// one 代表第一个答案
type ans118 struct {
one [][]int
}
func Test_Problem118(t *testing.T) {
qs := []question118{
{
para118{2},
ans118{[][]int{... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0118.Pascals-Triangle/118. Pascals Triangle.go | leetcode/0118.Pascals-Triangle/118. Pascals Triangle.go | package leetcode
func generate(numRows int) [][]int {
result := [][]int{}
for i := 0; i < numRows; i++ {
row := []int{}
for j := 0; j < i+1; j++ {
if j == 0 || j == i {
row = append(row, 1)
} else if i > 1 {
row = append(row, result[i-1][j-1]+result[i-1][j])
}
}
result = append(result, row)
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.