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/0327.Count-of-Range-Sum/327. Count of Range Sum.go | leetcode/0327.Count-of-Range-Sum/327. Count of Range Sum.go | package leetcode
import (
"sort"
"github.com/halfrost/LeetCode-Go/template"
)
// 解法一 线段树,时间复杂度 O(n log n)
func countRangeSum(nums []int, lower int, upper int) int {
if len(nums) == 0 {
return 0
}
st, prefixSum, sumMap, sumArray, res := template.SegmentCountTree{}, make([]int, len(nums)), make(map[int]int, 0),... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0327.Count-of-Range-Sum/327. Count of Range Sum_test.go | leetcode/0327.Count-of-Range-Sum/327. Count of Range Sum_test.go | package leetcode
import (
"fmt"
"testing"
)
type question327 struct {
para327
ans327
}
// para 是参数
// one 代表第一个参数
type para327 struct {
nums []int
lower int
upper int
}
// ans 是答案
// one 代表第一个答案
type ans327 struct {
one int
}
func Test_Problem327(t *testing.T) {
qs := []question327{
{
para327{[]in... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1200.Minimum-Absolute-Difference/1200. Minimum Absolute Difference.go | leetcode/1200.Minimum-Absolute-Difference/1200. Minimum Absolute Difference.go | package leetcode
import (
"math"
"sort"
)
func minimumAbsDifference(arr []int) [][]int {
minDiff, res := math.MaxInt32, [][]int{}
sort.Ints(arr)
for i := 1; i < len(arr); i++ {
if arr[i]-arr[i-1] < minDiff {
minDiff = arr[i] - arr[i-1]
}
if minDiff == 1 {
break
}
}
for i := 1; i < len(arr); i++ {... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1200.Minimum-Absolute-Difference/1200. Minimum Absolute Difference_test.go | leetcode/1200.Minimum-Absolute-Difference/1200. Minimum Absolute Difference_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1200 struct {
para1200
ans1200
}
// para 是参数
// one 代表第一个参数
type para1200 struct {
arr []int
}
// ans 是答案
// one 代表第一个答案
type ans1200 struct {
one [][]int
}
func Test_Problem1200(t *testing.T) {
qs := []question1200{
{
para1200{[]int{4, 2, 1, 3... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0557.Reverse-Words-in-a-String-III/557. Reverse Words in a String III.go | leetcode/0557.Reverse-Words-in-a-String-III/557. Reverse Words in a String III.go | package leetcode
import (
"strings"
)
func reverseWords(s string) string {
ss := strings.Split(s, " ")
for i, s := range ss {
ss[i] = revers(s)
}
return strings.Join(ss, " ")
}
func revers(s string) string {
bytes := []byte(s)
i, j := 0, len(bytes)-1
for i < j {
bytes[i], bytes[j] = bytes[j], bytes[i]
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0557.Reverse-Words-in-a-String-III/557. Reverse Words in a String III_test.go | leetcode/0557.Reverse-Words-in-a-String-III/557. Reverse Words in a String III_test.go | package leetcode
import (
"fmt"
"testing"
)
type question557 struct {
para557
ans557
}
// para 是参数
// one 代表第一个参数
type para557 struct {
s string
}
// ans 是答案
// one 代表第一个答案
type ans557 struct {
one string
}
func Test_Problem557(t *testing.T) {
qs := []question557{
{
para557{"Let's take LeetCode conte... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1160.Find-Words-That-Can-Be-Formed-by-Characters/1160. Find Words That Can Be Formed by Characters_test.go | leetcode/1160.Find-Words-That-Can-Be-Formed-by-Characters/1160. Find Words That Can Be Formed by Characters_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1160 struct {
para1160
ans1160
}
// para 是参数
// one 代表第一个参数
type para1160 struct {
words []string
chars string
}
// ans 是答案
// one 代表第一个答案
type ans1160 struct {
one int
}
func Test_Problem1160(t *testing.T) {
qs := []question1160{
{
para1160{[... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1160.Find-Words-That-Can-Be-Formed-by-Characters/1160. Find Words That Can Be Formed by Characters.go | leetcode/1160.Find-Words-That-Can-Be-Formed-by-Characters/1160. Find Words That Can Be Formed by Characters.go | package leetcode
func countCharacters(words []string, chars string) int {
count, res := make([]int, 26), 0
for i := 0; i < len(chars); i++ {
count[chars[i]-'a']++
}
for _, w := range words {
if canBeFormed(w, count) {
res += len(w)
}
}
return res
}
func canBeFormed(w string, c []int) bool {
count := ma... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0862.Shortest-Subarray-with-Sum-at-Least-K/862. Shortest Subarray with Sum at Least K_test.go | leetcode/0862.Shortest-Subarray-with-Sum-at-Least-K/862. Shortest Subarray with Sum at Least K_test.go | package leetcode
import (
"fmt"
"testing"
)
type question862 struct {
para862
ans862
}
// para 是参数
// one 代表第一个参数
type para862 struct {
A []int
K int
}
// ans 是答案
// one 代表第一个答案
type ans862 struct {
one int
}
func Test_Problem862(t *testing.T) {
qs := []question862{
{
para862{[]int{1}, 1},
ans862{... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0862.Shortest-Subarray-with-Sum-at-Least-K/862. Shortest Subarray with Sum at Least K.go | leetcode/0862.Shortest-Subarray-with-Sum-at-Least-K/862. Shortest Subarray with Sum at Least K.go | package leetcode
func shortestSubarray(A []int, K int) int {
res, prefixSum := len(A)+1, make([]int, len(A)+1)
for i := 0; i < len(A); i++ {
prefixSum[i+1] = prefixSum[i] + A[i]
}
// deque 中保存递增的 prefixSum 下标
deque := []int{}
for i := range prefixSum {
// 下面这个循环希望能找到 [deque[0], i] 区间内累加和 >= K,如果找到了就更新答案
fo... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0354.Russian-Doll-Envelopes/354. Russian Doll Envelopes_test.go | leetcode/0354.Russian-Doll-Envelopes/354. Russian Doll Envelopes_test.go | package leetcode
import (
"fmt"
"testing"
)
type question354 struct {
para354
ans354
}
// para 是参数
// one 代表第一个参数
type para354 struct {
envelopes [][]int
}
// ans 是答案
// one 代表第一个答案
type ans354 struct {
one int
}
func Test_Problem354(t *testing.T) {
qs := []question354{
{
para354{[][]int{{5, 4}, {6, ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0354.Russian-Doll-Envelopes/354. Russian Doll Envelopes.go | leetcode/0354.Russian-Doll-Envelopes/354. Russian Doll Envelopes.go | package leetcode
import (
"sort"
)
type sortEnvelopes [][]int
func (s sortEnvelopes) Len() int {
return len(s)
}
func (s sortEnvelopes) Less(i, j int) bool {
if s[i][0] == s[j][0] {
return s[i][1] > s[j][1]
}
return s[i][0] < s[j][0]
}
func (s sortEnvelopes) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func m... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0762.Prime-Number-of-Set-Bits-in-Binary-Representation/762. Prime Number of Set Bits in Binary Representation_test.go | leetcode/0762.Prime-Number-of-Set-Bits-in-Binary-Representation/762. Prime Number of Set Bits in Binary Representation_test.go | package leetcode
import (
"fmt"
"testing"
)
type question762 struct {
para762
ans762
}
// para 是参数
// one 代表第一个参数
type para762 struct {
l int
r int
}
// ans 是答案
// one 代表第一个答案
type ans762 struct {
one int
}
func Test_Problem762(t *testing.T) {
qs := []question762{
{
para762{6, 10},
ans762{4},
}... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0762.Prime-Number-of-Set-Bits-in-Binary-Representation/762. Prime Number of Set Bits in Binary Representation.go | leetcode/0762.Prime-Number-of-Set-Bits-in-Binary-Representation/762. Prime Number of Set Bits in Binary Representation.go | package leetcode
import "math/bits"
func countPrimeSetBits(L int, R int) int {
counter := 0
for i := L; i <= R; i++ {
if isPrime(bits.OnesCount(uint(i))) {
counter++
}
}
return counter
}
func isPrime(x int) bool {
return x == 2 || x == 3 || x == 5 || x == 7 || x == 11 || x == 13 || x == 17 || x == 19
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0208.Implement-Trie-Prefix-Tree/208. Implement Trie (Prefix Tree)_test.go | leetcode/0208.Implement-Trie-Prefix-Tree/208. Implement Trie (Prefix Tree)_test.go | package leetcode
import (
"fmt"
"testing"
)
func Test_Problem208(t *testing.T) {
obj := Constructor208()
fmt.Printf("obj = %v\n", obj)
obj.Insert("apple")
fmt.Printf("obj = %v\n", obj)
param1 := obj.Search("apple")
fmt.Printf("param_1 = %v obj = %v\n", param1, obj)
param2 := obj.Search("app")
fmt.Printf("pa... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0208.Implement-Trie-Prefix-Tree/208. Implement Trie (Prefix Tree).go | leetcode/0208.Implement-Trie-Prefix-Tree/208. Implement Trie (Prefix Tree).go | package leetcode
type Trie struct {
isWord bool
children map[rune]*Trie
}
/** Initialize your data structure here. */
func Constructor208() Trie {
return Trie{isWord: false, children: make(map[rune]*Trie)}
}
/** Inserts a word into the trie. */
func (this *Trie) Insert(word string) {
parent := this
for _, ch ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0222.Count-Complete-Tree-Nodes/222. Count Complete Tree Nodes.go | leetcode/0222.Count-Complete-Tree-Nodes/222. Count Complete Tree Nodes.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 countNodes(root *TreeNode) int {
if root == ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0222.Count-Complete-Tree-Nodes/222. Count Complete Tree Nodes_test.go | leetcode/0222.Count-Complete-Tree-Nodes/222. Count Complete Tree Nodes_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question222 struct {
para222
ans222
}
// para 是参数
// one 代表第一个参数
type para222 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans222 struct {
one int
}
func Test_Problem222(t *testing.T) {
qs := []question22... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1184.Distance-Between-Bus-Stops/1184. Distance Between Bus Stops.go | leetcode/1184.Distance-Between-Bus-Stops/1184. Distance Between Bus Stops.go | package leetcode
func distanceBetweenBusStops(distance []int, start int, destination int) int {
clockwiseDis, counterclockwiseDis, n := 0, 0, len(distance)
for i := start; i != destination; i = (i + 1) % n {
clockwiseDis += distance[i]
}
for i := destination; i != start; i = (i + 1) % n {
counterclockwiseDis +... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1184.Distance-Between-Bus-Stops/1184. Distance Between Bus Stops_test.go | leetcode/1184.Distance-Between-Bus-Stops/1184. Distance Between Bus Stops_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1184 struct {
para1184
ans1184
}
// para 是参数
// one 代表第一个参数
type para1184 struct {
distance []int
start int
destination int
}
// ans 是答案
// one 代表第一个答案
type ans1184 struct {
one int
}
func Test_Problem1184(t *testing.T) {
qs := []question1... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0684.Redundant-Connection/684. Redundant Connection_test.go | leetcode/0684.Redundant-Connection/684. Redundant Connection_test.go | package leetcode
import (
"fmt"
"testing"
)
type question684 struct {
para684
ans684
}
// para 是参数
// one 代表第一个参数
type para684 struct {
one [][]int
}
// ans 是答案
// one 代表第一个答案
type ans684 struct {
one []int
}
func Test_Problem684(t *testing.T) {
qs := []question684{
{
para684{[][]int{{1, 2}, {1, 3}, ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0684.Redundant-Connection/684. Redundant Connection.go | leetcode/0684.Redundant-Connection/684. Redundant Connection.go | package leetcode
import (
"github.com/halfrost/LeetCode-Go/template"
)
func findRedundantConnection(edges [][]int) []int {
if len(edges) == 0 {
return []int{}
}
uf, res := template.UnionFind{}, []int{}
uf.Init(len(edges) + 1)
for i := 0; i < len(edges); i++ {
if uf.Find(edges[i][0]) != uf.Find(edges[i][1]) ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0371.Sum-of-Two-Integers/371. Sum of Two Integers.go | leetcode/0371.Sum-of-Two-Integers/371. Sum of Two Integers.go | package leetcode
func getSum(a int, b int) int {
if a == 0 {
return b
}
if b == 0 {
return a
}
// (a & b)<<1 计算的是进位
// a ^ b 计算的是不带进位的加法
return getSum((a&b)<<1, a^b)
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0371.Sum-of-Two-Integers/371. Sum of Two Integers_test.go | leetcode/0371.Sum-of-Two-Integers/371. Sum of Two Integers_test.go | package leetcode
import (
"fmt"
"testing"
)
type question371 struct {
para371
ans371
}
// para 是参数
// one 代表第一个参数
type para371 struct {
a int
b int
}
// ans 是答案
// one 代表第一个答案
type ans371 struct {
one int
}
func Test_Problem371(t *testing.T) {
qs := []question371{
{
para371{1, 2},
ans371{3},
},... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0136.Single-Number/136. Single Number_test.go | leetcode/0136.Single-Number/136. Single Number_test.go | package leetcode
import (
"fmt"
"testing"
)
type question136 struct {
para136
ans136
}
// para 是参数
// one 代表第一个参数
type para136 struct {
s []int
}
// ans 是答案
// one 代表第一个答案
type ans136 struct {
one int
}
func Test_Problem136(t *testing.T) {
qs := []question136{
{
para136{[]int{2, 2, 1}},
ans136{1},... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0136.Single-Number/136. Single Number.go | leetcode/0136.Single-Number/136. Single Number.go | package leetcode
func singleNumber(nums []int) int {
result := 0
for i := 0; i < len(nums); i++ {
result ^= nums[i]
}
return result
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0174.Dungeon-Game/174. Dungeon Game.go | leetcode/0174.Dungeon-Game/174. Dungeon Game.go | package leetcode
import "math"
// 解法一 动态规划
func calculateMinimumHP(dungeon [][]int) int {
if len(dungeon) == 0 {
return 0
}
m, n := len(dungeon), len(dungeon[0])
dp := make([][]int, m)
for i := 0; i < m; i++ {
dp[i] = make([]int, n)
}
dp[m-1][n-1] = max(1-dungeon[m-1][n-1], 1)
for i := n - 2; i >= 0; i-- ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0174.Dungeon-Game/174. Dungeon Game_test.go | leetcode/0174.Dungeon-Game/174. Dungeon Game_test.go | package leetcode
import (
"fmt"
"testing"
)
type question174 struct {
para174
ans174
}
// para 是参数
// one 代表第一个参数
type para174 struct {
s [][]int
}
// ans 是答案
// one 代表第一个答案
type ans174 struct {
one int
}
func Test_Problem174(t *testing.T) {
qs := []question174{
{
para174{[][]int{{2, 1}, {1, -1}}},
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0867.Transpose-Matrix/867. Transpose Matrix.go | leetcode/0867.Transpose-Matrix/867. Transpose Matrix.go | package leetcode
func transpose(A [][]int) [][]int {
row, col, result := len(A), len(A[0]), make([][]int, len(A[0]))
for i := range result {
result[i] = make([]int, row)
}
for i := 0; i < row; i++ {
for j := 0; j < col; j++ {
result[j][i] = A[i][j]
}
}
return result
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0867.Transpose-Matrix/867. Transpose Matrix_test.go | leetcode/0867.Transpose-Matrix/867. Transpose Matrix_test.go | package leetcode
import (
"fmt"
"testing"
)
type question867 struct {
para867
ans867
}
// para 是参数
// one 代表第一个参数
type para867 struct {
A [][]int
}
// ans 是答案
// one 代表第一个答案
type ans867 struct {
B [][]int
}
func Test_Problem867(t *testing.T) {
qs := []question867{
{
para867{[][]int{{1, 2, 3}, {4, 5, ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2038.Remove-Colored-Pieces-if-Both-Neighbors-are-the-Same-Color/2038.Remove Colored Pieces if Both Neighbors are the Same Color.go | leetcode/2038.Remove-Colored-Pieces-if-Both-Neighbors-are-the-Same-Color/2038.Remove Colored Pieces if Both Neighbors are the Same Color.go | package leetcode
func winnerOfGame(colors string) bool {
As, Bs := 0, 0
Acont, Bcont := 0, 0
for _, color := range colors {
if color == 'A' {
Acont += 1
Bcont = 0
} else {
Bcont += 1
Acont = 0
}
if Acont >= 3 {
As += Acont - 2
}
if Bcont >= 3 {
Bs += Bcont - 2
}
}
if As > Bs {
re... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2038.Remove-Colored-Pieces-if-Both-Neighbors-are-the-Same-Color/2038.Remove Colored Pieces if Both Neighbors are the Same Color_test.go | leetcode/2038.Remove-Colored-Pieces-if-Both-Neighbors-are-the-Same-Color/2038.Remove Colored Pieces if Both Neighbors are the Same Color_test.go | package leetcode
import (
"fmt"
"testing"
)
type question2038 struct {
para2038
ans2038
}
// para 是参数
type para2038 struct {
colors string
}
// ans 是答案
type ans2038 struct {
ans bool
}
func Test_Problem2038(t *testing.T) {
qs := []question2038{
{
para2038{"AAABABB"},
ans2038{true},
},
{
pa... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls.go | leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls.go | package leetcode
import (
"container/heap"
)
// 解法一 贪心 + 二分搜索
func maxProfit(inventory []int, orders int) int {
maxItem, thresholdValue, count, res, mod := 0, -1, 0, 0, 1000000007
for i := 0; i < len(inventory); i++ {
if inventory[i] > maxItem {
maxItem = inventory[i]
}
}
low, high := 0, maxItem
for low ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls_test.go | leetcode/1648.Sell-Diminishing-Valued-Colored-Balls/1648. Sell Diminishing-Valued Colored Balls_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1648 struct {
para1648
ans1648
}
// para 是参数
// one 代表第一个参数
type para1648 struct {
inventory []int
orders int
}
// ans 是答案
// one 代表第一个答案
type ans1648 struct {
one int
}
func Test_Problem1648(t *testing.T) {
qs := []question1648{
{
para1648... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1178.Number-of-Valid-Words-for-Each-Puzzle/1178. Number of Valid Words for Each Puzzle_test.go | leetcode/1178.Number-of-Valid-Words-for-Each-Puzzle/1178. Number of Valid Words for Each Puzzle_test.go | package leetcode
import (
"reflect"
"testing"
)
func Test_findNumOfValidWords(t *testing.T) {
words1 := []string{"aaaa", "asas", "able", "ability", "actt", "actor", "access"}
puzzles1 := []string{"aboveyz", "abrodyz", "abslute", "absoryz", "actresz", "gaswxyz"}
type args struct {
words []string
puzzles [... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1178.Number-of-Valid-Words-for-Each-Puzzle/1178. Number of Valid Words for Each Puzzle.go | leetcode/1178.Number-of-Valid-Words-for-Each-Puzzle/1178. Number of Valid Words for Each Puzzle.go | package leetcode
/*
匹配跟单词中的字母顺序,字母个数都无关,可以用 bitmap 压缩
1. 记录 word 中 利用 map 记录各种 bit 标示的个数
2. puzzles 中各个字母都不相同! 记录 bitmap,然后搜索子空间中各种 bit 标识的个数的和
因为 puzzles 长度最长是7,所以搜索空间 2^7
*/
func findNumOfValidWords(words []string, puzzles []string) []int {
wordBitStatusMap, res := make(map[uint32]int, 0), []int{}
for _, w :... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target.go | leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target.go | package leetcode
func findBestValue(arr []int, target int) int {
low, high := 0, 100000
for low < high {
mid := low + (high-low)>>1
if calculateSum(arr, mid) < target {
low = mid + 1
} else {
high = mid
}
}
if high == 100000 {
res := 0
for _, num := range arr {
if res < num {
res = num
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target_test.go | leetcode/1300.Sum-of-Mutated-Array-Closest-to-Target/1300. Sum of Mutated Array Closest to Target_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1300 struct {
para1300
ans1300
}
// para 是参数
// one 代表第一个参数
type para1300 struct {
arr []int
target int
}
// ans 是答案
// one 代表第一个答案
type ans1300 struct {
one int
}
func Test_Problem1300(t *testing.T) {
qs := []question1300{
{
para1300{[]int... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0382.Linked-List-Random-Node/382. Linked List Random Node.go | leetcode/0382.Linked-List-Random-Node/382. Linked List Random Node.go | package leetcode
import (
"math/rand"
"github.com/halfrost/LeetCode-Go/structures"
)
// ListNode define
type ListNode = structures.ListNode
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
type Solution struct {
head *ListNode
}
/*
- @param head... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0382.Linked-List-Random-Node/382. Linked List Random Node_test.go | leetcode/0382.Linked-List-Random-Node/382. Linked List Random Node_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
func Test_Problem382(t *testing.T) {
header := structures.Ints2List([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0})
obj := Constructor(header)
fmt.Printf("obj = %v\n", structures.List2Ints(header))
param1 := obj.GetRandom()
fmt.Pri... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1465.Maximum-Area-of-a-Piece-of-Cake-After-Horizontal-and-Vertical-Cuts/1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts.go | leetcode/1465.Maximum-Area-of-a-Piece-of-Cake-After-Horizontal-and-Vertical-Cuts/1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts.go | package leetcode
import "sort"
func maxArea(h int, w int, horizontalCuts []int, verticalCuts []int) int {
sort.Ints(horizontalCuts)
sort.Ints(verticalCuts)
maxw, maxl := horizontalCuts[0], verticalCuts[0]
for i, c := range horizontalCuts[1:] {
if c-horizontalCuts[i] > maxw {
maxw = c - horizontalCuts[i]
}
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1465.Maximum-Area-of-a-Piece-of-Cake-After-Horizontal-and-Vertical-Cuts/1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts_test.go | leetcode/1465.Maximum-Area-of-a-Piece-of-Cake-After-Horizontal-and-Vertical-Cuts/1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1465 struct {
para1465
ans1465
}
// para 是参数
// one 代表第一个参数
type para1465 struct {
h int
w int
horizontalCuts []int
verticalCuts []int
}
// ans 是答案
// one 代表第一个答案
type ans1465 struct {
one int
}
func Test_Problem1465(t *t... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0783.Minimum-Distance-Between-BST-Nodes/783. Minimum Distance Between BST Nodes_test.go | leetcode/0783.Minimum-Distance-Between-BST-Nodes/783. Minimum Distance Between BST Nodes_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question783 struct {
para783
ans783
}
// para 是参数
// one 代表第一个参数
type para783 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans783 struct {
one int
}
func Test_Problem783(t *testing.T) {
qs := []question78... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0783.Minimum-Distance-Between-BST-Nodes/783. Minimum Distance Between BST Nodes.go | leetcode/0783.Minimum-Distance-Between-BST-Nodes/783. Minimum Distance Between BST Nodes.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 minDiffInBST(root *TreeNode) int {
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0101.Symmetric-Tree/101. Symmetric Tree.go | leetcode/0101.Symmetric-Tree/101. Symmetric 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
* }
*/
// 解法一 dfs
func isSymmetric(root *TreeNode) bool {... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0101.Symmetric-Tree/101. Symmetric Tree_test.go | leetcode/0101.Symmetric-Tree/101. Symmetric Tree_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question101 struct {
para101
ans101
}
// para 是参数
// one 代表第一个参数
type para101 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans101 struct {
one bool
}
func Test_Problem101(t *testing.T) {
qs := []question1... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2037.Minimum-Number-of-Moves-to-Seat-Everyone/2037.Minimum Number of Moves to Seat Everyone.go | leetcode/2037.Minimum-Number-of-Moves-to-Seat-Everyone/2037.Minimum Number of Moves to Seat Everyone.go | package leetcode
import "sort"
func minMovesToSeat(seats []int, students []int) int {
sort.Ints(seats)
sort.Ints(students)
n := len(students)
moves := 0
for i := 0; i < n; i++ {
moves += abs(seats[i], students[i])
}
return moves
}
func abs(a, b int) int {
if a > b {
return a - b
}
return b - a
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2037.Minimum-Number-of-Moves-to-Seat-Everyone/2037.Minimum Number of Moves to Seat Everyone_test.go | leetcode/2037.Minimum-Number-of-Moves-to-Seat-Everyone/2037.Minimum Number of Moves to Seat Everyone_test.go | package leetcode
import (
"fmt"
"testing"
)
type question2037 struct {
para2037
ans2037
}
// para 是参数
type para2037 struct {
seats []int
students []int
}
// ans 是答案
type ans2037 struct {
ans int
}
func Test_Problem2037(t *testing.T) {
qs := []question2037{
{
para2037{[]int{3, 1, 5}, []int{2, 7, 4... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0209.Minimum-Size-Subarray-Sum/209. Minimum Size Subarray Sum.go | leetcode/0209.Minimum-Size-Subarray-Sum/209. Minimum Size Subarray Sum.go | package leetcode
func minSubArrayLen(target int, nums []int) int {
left, sum, res := 0, 0, len(nums)+1
for right, v := range nums {
sum += v
for sum >= target {
res = min(res, right-left+1)
sum -= nums[left]
left++
}
}
if res == len(nums)+1 {
return 0
}
return res
}
func min(a int, b int) int {... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0209.Minimum-Size-Subarray-Sum/209. Minimum Size Subarray Sum_test.go | leetcode/0209.Minimum-Size-Subarray-Sum/209. Minimum Size Subarray Sum_test.go | package leetcode
import (
"fmt"
"testing"
)
type question209 struct {
para209
ans209
}
// para 是参数
// one 代表第一个参数
type para209 struct {
s int
one []int
}
// ans 是答案
// one 代表第一个答案
type ans209 struct {
one int
}
func Test_Problem209(t *testing.T) {
qs := []question209{
{
para209{7, []int{2, 3, 1, 2... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0909.Snakes-and-Ladders/909. Snakes and Ladders.go | leetcode/0909.Snakes-and-Ladders/909. Snakes and Ladders.go | package leetcode
type pair struct {
id, step int
}
func snakesAndLadders(board [][]int) int {
n := len(board)
visited := make([]bool, n*n+1)
queue := []pair{{1, 0}}
for len(queue) > 0 {
p := queue[0]
queue = queue[1:]
for i := 1; i <= 6; i++ {
nxt := p.id + i
if nxt > n*n { // 超出边界
break
}
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0909.Snakes-and-Ladders/909. Snakes and Ladders_test.go | leetcode/0909.Snakes-and-Ladders/909. Snakes and Ladders_test.go | package leetcode
import (
"fmt"
"testing"
)
type question909 struct {
para909
ans909
}
// para 是参数
// one 代表第一个参数
type para909 struct {
one [][]int
}
// ans 是答案
// one 代表第一个答案
type ans909 struct {
one int
}
func Test_Problem909(t *testing.T) {
qs := []question909{
{
para909{[][]int{
{-1, -1, -1, -1... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0081.Search-in-Rotated-Sorted-Array-II/81. Search in Rotated Sorted Array II_test.go | leetcode/0081.Search-in-Rotated-Sorted-Array-II/81. Search in Rotated Sorted Array II_test.go | package leetcode
import (
"fmt"
"testing"
)
type question81 struct {
para81
ans81
}
// para 是参数
// one 代表第一个参数
type para81 struct {
nums []int
target int
}
// ans 是答案
// one 代表第一个答案
type ans81 struct {
one bool
}
func Test_Problem81(t *testing.T) {
qs := []question81{
{
para81{[]int{2, 5, 6, 0, 0,... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0081.Search-in-Rotated-Sorted-Array-II/81. Search in Rotated Sorted Array II.go | leetcode/0081.Search-in-Rotated-Sorted-Array-II/81. Search in Rotated Sorted Array II.go | package leetcode
func search(nums []int, target int) bool {
if len(nums) == 0 {
return false
}
low, high := 0, len(nums)-1
for low <= high {
mid := low + (high-low)>>1
if nums[mid] == target {
return true
} else if nums[mid] > nums[low] { // 在数值大的一部分区间里
if nums[low] <= target && target < nums[mid] {
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name.go | leetcode/0925.Long-Pressed-Name/925. Long Pressed Name.go | package leetcode
func isLongPressedName(name string, typed string) bool {
if len(name) == 0 && len(typed) == 0 {
return true
}
if (len(name) == 0 && len(typed) != 0) || (len(name) != 0 && len(typed) == 0) {
return false
}
i, j := 0, 0
for i < len(name) && j < len(typed) {
if name[i] != typed[j] {
return... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0925.Long-Pressed-Name/925. Long Pressed Name_test.go | leetcode/0925.Long-Pressed-Name/925. Long Pressed Name_test.go | package leetcode
import (
"fmt"
"testing"
)
type question925 struct {
para925
ans925
}
// para 是参数
// one 代表第一个参数
type para925 struct {
name string
typed string
}
// ans 是答案
// one 代表第一个答案
type ans925 struct {
one bool
}
func Test_Problem925(t *testing.T) {
qs := []question925{
{
para925{"alex", "a... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0520.Detect-Capital/520.Detect Capital_test.go | leetcode/0520.Detect-Capital/520.Detect Capital_test.go | package leetcode
import (
"fmt"
"testing"
)
type question520 struct {
para520
ans520
}
// para 是参数
type para520 struct {
word string
}
// ans 是答案
type ans520 struct {
ans bool
}
func Test_Problem520(t *testing.T) {
qs := []question520{
{
para520{"USA"},
ans520{true},
},
{
para520{"FlaG"},
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0520.Detect-Capital/520.Detect Capital.go | leetcode/0520.Detect-Capital/520.Detect Capital.go | package leetcode
import "strings"
func detectCapitalUse(word string) bool {
wLower := strings.ToLower(word)
wUpper := strings.ToUpper(word)
wCaptial := strings.ToUpper(string(word[0])) + strings.ToLower(string(word[1:]))
if wCaptial == word || wLower == word || wUpper == word {
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/1017.Convert-to-Base-2/1017. Convert to Base -2.go | leetcode/1017.Convert-to-Base-2/1017. Convert to Base -2.go | package leetcode
import "strconv"
func baseNeg2(N int) string {
if N == 0 {
return "0"
}
res := ""
for N != 0 {
remainder := N % (-2)
N = N / (-2)
if remainder < 0 {
remainder += 2
N++
}
res = strconv.Itoa(remainder) + 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/1017.Convert-to-Base-2/1017. Convert to Base -2_test.go | leetcode/1017.Convert-to-Base-2/1017. Convert to Base -2_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1017 struct {
para1017
ans1017
}
// para 是参数
// one 代表第一个参数
type para1017 struct {
one int
}
// ans 是答案
// one 代表第一个答案
type ans1017 struct {
one string
}
func Test_Problem1017(t *testing.T) {
qs := []question1017{
{
para1017{2},
ans1017{"110... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0853.Car-Fleet/853. Car Fleet.go | leetcode/0853.Car-Fleet/853. Car Fleet.go | package leetcode
import (
"sort"
)
type car struct {
time float64
position int
}
// ByPosition define
type ByPosition []car
func (a ByPosition) Len() int { return len(a) }
func (a ByPosition) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByPosition) Less(i, j int) bool { return a[i].posit... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0853.Car-Fleet/853. Car Fleet_test.go | leetcode/0853.Car-Fleet/853. Car Fleet_test.go | package leetcode
import (
"fmt"
"testing"
)
type question853 struct {
para853
ans853
}
// para 是参数
// one 代表第一个参数
type para853 struct {
target int
position []int
speed []int
}
// ans 是答案
// one 代表第一个答案
type ans853 struct {
one int
}
func Test_Problem853(t *testing.T) {
qs := []question853{
{
p... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2021.Brightest-Position-on-Street/2021. Brightest Position on Street_test.go | leetcode/2021.Brightest-Position-on-Street/2021. Brightest Position on Street_test.go | package leetcode
import (
"fmt"
"testing"
)
type question2021 struct {
para2021
ans2021
}
// para 是参数
type para2021 struct {
lights [][]int
}
// ans 是答案
type ans2021 struct {
ans int
}
func Test_Problem2021(t *testing.T) {
qs := []question2021{
{
para2021{[][]int{{-3, 2}, {1, 2}, {3, 3}}},
ans2021... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2021.Brightest-Position-on-Street/2021. Brightest Position on Street.go | leetcode/2021.Brightest-Position-on-Street/2021. Brightest Position on Street.go | package leetcode
import (
"sort"
)
type lightItem struct {
index int
sign int
}
func brightestPosition(lights [][]int) int {
lightMap, lightItems := map[int]int{}, []lightItem{}
for _, light := range lights {
lightMap[light[0]-light[1]] += 1
lightMap[light[0]+light[1]+1] -= 1
}
for k, v := range lightMap... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0069.Sqrtx/69. Sqrt(x).go | leetcode/0069.Sqrtx/69. Sqrt(x).go | package leetcode
// 解法一 二分, 找到最后一个满足 n^2 <= x 的整数n
func mySqrt(x int) int {
l, r := 0, x
for l < r {
mid := (l + r + 1) / 2
if mid*mid > x {
r = mid - 1
} else {
l = mid
}
}
return l
}
// 解法二 牛顿迭代法 https://en.wikipedia.org/wiki/Integer_square_root
func mySqrt1(x int) int {
r := x
for r*r > x {
r... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0069.Sqrtx/69. Sqrt(x)_test.go | leetcode/0069.Sqrtx/69. Sqrt(x)_test.go | package leetcode
import (
"fmt"
"testing"
)
type question69 struct {
para69
ans69
}
// para 是参数
// one 代表第一个参数
type para69 struct {
one int
}
// ans 是答案
// one 代表第一个答案
type ans69 struct {
one int
}
func Test_Problem69(t *testing.T) {
qs := []question69{
{
para69{4},
ans69{2},
},
{
para69{8... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990352.Data-Stream-as-Disjoint-Intervals/352. Data Stream as Disjoint Intervals.go | leetcode/9990352.Data-Stream-as-Disjoint-Intervals/352. Data Stream as Disjoint Intervals.go | package leetcode
import (
"github.com/halfrost/LeetCode-Go/structures"
)
// Interval define
type Interval = structures.Interval
// SummaryRanges define
type SummaryRanges struct {
intervals []Interval
}
// Constructor352 define
func Constructor352() SummaryRanges {
return SummaryRanges{}
}
// AddNum define
func... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/9990352.Data-Stream-as-Disjoint-Intervals/352. Data Stream as Disjoint Intervals_test.go | leetcode/9990352.Data-Stream-as-Disjoint-Intervals/352. Data Stream as Disjoint Intervals_test.go | package leetcode
import (
"fmt"
"testing"
)
func Test_Problem352(t *testing.T) {
obj := Constructor352()
fmt.Printf("obj = %v\n", obj)
obj.AddNum(1)
fmt.Printf("Intervals = %v\n", obj.GetIntervals()) // [1,1]
obj.AddNum(3)
fmt.Printf("Intervals = %v\n", obj.GetIntervals()) // [1,1] [3,3]
obj.AddNum(7)
fmt.P... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1052.Grumpy-Bookstore-Owner/1052. Grumpy Bookstore Owner.go | leetcode/1052.Grumpy-Bookstore-Owner/1052. Grumpy Bookstore Owner.go | package leetcode
// 解法一 滑动窗口优化版
func maxSatisfied(customers []int, grumpy []int, X int) int {
customer0, customer1, maxCustomer1, left, right := 0, 0, 0, 0, 0
for ; right < len(customers); right++ {
if grumpy[right] == 0 {
customer0 += customers[right]
} else {
customer1 += customers[right]
for right-le... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1052.Grumpy-Bookstore-Owner/1052. Grumpy Bookstore Owner_test.go | leetcode/1052.Grumpy-Bookstore-Owner/1052. Grumpy Bookstore Owner_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1052 struct {
para1052
ans1052
}
// para 是参数
// one 代表第一个参数
type para1052 struct {
customers []int
grumpy []int
x int
}
// ans 是答案
// one 代表第一个答案
type ans1052 struct {
one int
}
func Test_Problem1052(t *testing.T) {
qs := []question1052{... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0509.Fibonacci-Number/509. Fibonacci Number.go | leetcode/0509.Fibonacci-Number/509. Fibonacci Number.go | package leetcode
import "math"
// 解法一 递归法 时间复杂度 O(2^n),空间复杂度 O(n)
func fib(N int) int {
if N <= 1 {
return N
}
return fib(N-1) + fib(N-2)
}
// 解法二 自底向上的记忆化搜索 时间复杂度 O(n),空间复杂度 O(n)
func fib1(N int) int {
if N <= 1 {
return N
}
cache := map[int]int{0: 0, 1: 1}
for i := 2; i <= N; i++ {
cache[i] = cache[i-... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0509.Fibonacci-Number/509. Fibonacci Number_test.go | leetcode/0509.Fibonacci-Number/509. Fibonacci Number_test.go | package leetcode
import (
"fmt"
"testing"
)
type question509 struct {
para509
ans509
}
// para 是参数
// one 代表第一个参数
type para509 struct {
one int
}
// ans 是答案
// one 代表第一个答案
type ans509 struct {
one int
}
func Test_Problem509(t *testing.T) {
qs := []question509{
{
para509{1},
ans509{1},
},
{
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2170.Minimum-Operations-to-Make-the-Array-Alternating/2170. Minimum Operations to Make the Array Alternating_test.go | leetcode/2170.Minimum-Operations-to-Make-the-Array-Alternating/2170. Minimum Operations to Make the Array Alternating_test.go | package leetcode
import (
"fmt"
"testing"
)
type question2170 struct {
para2170
ans2170
}
// para 是参数
// one 代表第一个参数
type para2170 struct {
nums []int
}
// ans 是答案
// one 代表第一个答案
type ans2170 struct {
one int
}
func Test_Problem1(t *testing.T) {
qs := []question2170{
{
para2170{[]int{1}},
ans2170{... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/2170.Minimum-Operations-to-Make-the-Array-Alternating/2170. Minimum Operations to Make the Array Alternating.go | leetcode/2170.Minimum-Operations-to-Make-the-Array-Alternating/2170. Minimum Operations to Make the Array Alternating.go | package leetcode
import (
"sort"
)
type node struct {
value int
count int
}
func minimumOperations(nums []int) int {
if len(nums) == 1 {
return 0
}
res, odd, even, oddMap, evenMap := 0, []node{}, []node{}, map[int]int{}, map[int]int{}
for i := 0; i < len(nums); i += 2 {
evenMap[nums[i]]++
}
for k, v :=... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0421.Maximum-XOR-of-Two-Numbers-in-an-Array/421. Maximum XOR of Two Numbers in an Array_test.go | leetcode/0421.Maximum-XOR-of-Two-Numbers-in-an-Array/421. Maximum XOR of Two Numbers in an Array_test.go | package leetcode
import (
"fmt"
"testing"
)
type question421 struct {
para421
ans421
}
// para 是参数
// one 代表第一个参数
type para421 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans421 struct {
one int
}
func Test_Problem421(t *testing.T) {
qs := []question421{
{
para421{[]int{3, 10, 5, 25, 2, 8}},
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0421.Maximum-XOR-of-Two-Numbers-in-an-Array/421. Maximum XOR of Two Numbers in an Array.go | leetcode/0421.Maximum-XOR-of-Two-Numbers-in-an-Array/421. Maximum XOR of Two Numbers in an Array.go | package leetcode
// 解法一
func findMaximumXOR(nums []int) int {
maxResult, mask := 0, 0
/*The maxResult is a record of the largest XOR we got so far. if it's 11100 at i = 2, it means
before we reach the last two bits, 11100 is the biggest XOR we have, and we're going to explore
whether we can get another two '1'... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0086.Partition-List/86. Partition List.go | leetcode/0086.Partition-List/86. Partition 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 partition(head *ListNode, x int) *ListNode {
beforeHead ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0086.Partition-List/86. Partition List_test.go | leetcode/0086.Partition-List/86. Partition List_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question86 struct {
para86
ans86
}
// para 是参数
// one 代表第一个参数
type para86 struct {
one []int
x int
}
// ans 是答案
// one 代表第一个答案
type ans86 struct {
one []int
}
func Test_Problem86(t *testing.T) {
qs := []quest... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0441.Arranging-Coins/441. Arranging Coins_test.go | leetcode/0441.Arranging-Coins/441. Arranging Coins_test.go | package leetcode
import (
"fmt"
"testing"
)
type question441 struct {
para441
ans441
}
// para 是参数
// one 代表第一个参数
type para441 struct {
n int
}
// ans 是答案
// one 代表第一个答案
type ans441 struct {
one int
}
func Test_Problem441(t *testing.T) {
qs := []question441{
{
para441{5},
ans441{2},
},
{
p... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0441.Arranging-Coins/441. Arranging Coins.go | leetcode/0441.Arranging-Coins/441. Arranging Coins.go | package leetcode
import "math"
// 解法一 数学公式
func arrangeCoins(n int) int {
if n <= 0 {
return 0
}
x := math.Sqrt(2*float64(n)+0.25) - 0.5
return int(x)
}
// 解法二 模拟
func arrangeCoins1(n int) int {
k := 1
for n >= k {
n -= k
k++
}
return k - 1
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0997.Find-the-Town-Judge/997.Find the Town Judge_test.go | leetcode/0997.Find-the-Town-Judge/997.Find the Town Judge_test.go | package leetcode
import (
"fmt"
"testing"
)
type question997 struct {
para997
ans997
}
// para 是参数
type para997 struct {
n int
trust [][]int
}
// ans 是答案
type ans997 struct {
ans int
}
func Test_Problem997(t *testing.T) {
qs := []question997{
{
para997{2, [][]int{{1, 2}}},
ans997{2},
},
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0997.Find-the-Town-Judge/997.Find the Town Judge.go | leetcode/0997.Find-the-Town-Judge/997.Find the Town Judge.go | package leetcode
func findJudge(n int, trust [][]int) int {
if n == 1 && len(trust) == 0 {
return 1
}
judges := make(map[int]int)
for _, v := range trust {
judges[v[1]] += 1
}
for _, v := range trust {
if _, ok := judges[v[0]]; ok {
delete(judges, v[0])
}
}
for k, v := range judges {
if v == n-1 {... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0128.Longest-Consecutive-Sequence/128. Longest Consecutive Sequence.go | leetcode/0128.Longest-Consecutive-Sequence/128. Longest Consecutive Sequence.go | package leetcode
import (
"github.com/halfrost/LeetCode-Go/template"
)
// 解法一 map,时间复杂度 O(n)
func longestConsecutive(nums []int) int {
res, numMap := 0, map[int]int{}
for _, num := range nums {
if numMap[num] == 0 {
left, right, sum := 0, 0, 0
if numMap[num-1] > 0 {
left = numMap[num-1]
} else {
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0128.Longest-Consecutive-Sequence/128. Longest Consecutive Sequence_test.go | leetcode/0128.Longest-Consecutive-Sequence/128. Longest Consecutive Sequence_test.go | package leetcode
import (
"fmt"
"testing"
)
type question128 struct {
para128
ans128
}
// para 是参数
// one 代表第一个参数
type para128 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans128 struct {
one int
}
func Test_Problem128(t *testing.T) {
qs := []question128{
{
para128{[]int{}},
ans128{0},
},... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0275.H-Index-II/275. H-Index II.go | leetcode/0275.H-Index-II/275. H-Index II.go | package leetcode
func hIndex275(citations []int) int {
low, high := 0, len(citations)-1
for low <= high {
mid := low + (high-low)>>1
if len(citations)-mid > citations[mid] {
low = mid + 1
} else {
high = mid - 1
}
}
return len(citations) - low
}
| go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0275.H-Index-II/275. H-Index II_test.go | leetcode/0275.H-Index-II/275. H-Index II_test.go | package leetcode
import (
"fmt"
"testing"
)
type question275 struct {
para275
ans275
}
// para 是参数
// one 代表第一个参数
type para275 struct {
one []int
}
// ans 是答案
// one 代表第一个答案
type ans275 struct {
one int
}
func Test_Problem275(t *testing.T) {
qs := []question275{
{
para275{[]int{3, 6, 9, 1}},
ans27... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0025.Reverse-Nodes-in-k-Group/25. Reverse Nodes in k Group_test.go | leetcode/0025.Reverse-Nodes-in-k-Group/25. Reverse Nodes in k Group_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question25 struct {
para25
ans25
}
// para 是参数
// one 代表第一个参数
type para25 struct {
one []int
two int
}
// ans 是答案
// one 代表第一个答案
type ans25 struct {
one []int
}
func Test_Problem25(t *testing.T) {
qs := []quest... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0025.Reverse-Nodes-in-k-Group/25. Reverse Nodes in k Group.go | leetcode/0025.Reverse-Nodes-in-k-Group/25. Reverse Nodes in k Group.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 reverseKGroup(head *ListNode, k int) *ListNode {
node := head
for i... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0699.Falling-Squares/699. Falling Squares.go | leetcode/0699.Falling-Squares/699. Falling Squares.go | package leetcode
import (
"sort"
"github.com/halfrost/LeetCode-Go/template"
)
func fallingSquares(positions [][]int) []int {
st, ans, posMap, maxHeight := template.SegmentTree{}, make([]int, 0, len(positions)), discretization(positions), 0
tmp := make([]int, len(posMap))
st.Init(tmp, func(i, j int) int {
retu... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0699.Falling-Squares/699. Falling Squares_test.go | leetcode/0699.Falling-Squares/699. Falling Squares_test.go | package leetcode
import (
"fmt"
"testing"
)
type question699 struct {
para699
ans699
}
// para 是参数
// one 代表第一个参数
type para699 struct {
one [][]int
}
// ans 是答案
// one 代表第一个答案
type ans699 struct {
one []int
}
func Test_Problem699(t *testing.T) {
qs := []question699{
{
para699{[][]int{{6, 1}, {9, 2}, ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0008.String-to-Integer-atoi/8. String to Integer atoi.go | leetcode/0008.String-to-Integer-atoi/8. String to Integer atoi.go | package leetcode
func myAtoi(s string) int {
maxInt, signAllowed, whitespaceAllowed, sign, digits := int64(2<<30), true, true, 1, []int{}
for _, c := range s {
if c == ' ' && whitespaceAllowed {
continue
}
if signAllowed {
if c == '+' {
signAllowed = false
whitespaceAllowed = false
continue
... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0008.String-to-Integer-atoi/8. String to Integer atoi_test.go | leetcode/0008.String-to-Integer-atoi/8. String to Integer atoi_test.go | package leetcode
import (
"fmt"
"testing"
)
type question8 struct {
para8
ans8
}
// para 是参数
// one 代表第一个参数
type para8 struct {
one string
}
// ans 是答案
// one 代表第一个答案
type ans8 struct {
one int
}
func Test_Problem8(t *testing.T) {
qs := []question8{
{
para8{"42"},
ans8{42},
},
{
para8{" ... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation_test.go | leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation_test.go | package leetcode
import (
"fmt"
"testing"
)
type question1640 struct {
para1640
ans1640
}
// para 是参数
// one 代表第一个参数
type para1640 struct {
arr []int
pieces [][]int
}
// ans 是答案
// one 代表第一个答案
type ans1640 struct {
one bool
}
func Test_Problem1640(t *testing.T) {
qs := []question1640{
{
para1640{... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation.go | leetcode/1640.Check-Array-Formation-Through-Concatenation/1640. Check Array Formation Through Concatenation.go | package leetcode
func canFormArray(arr []int, pieces [][]int) bool {
arrMap := map[int]int{}
for i, v := range arr {
arrMap[v] = i
}
for i := 0; i < len(pieces); i++ {
order := -1
for j := 0; j < len(pieces[i]); j++ {
if _, ok := arrMap[pieces[i][j]]; !ok {
return false
}
if order == -1 {
or... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0715.Range-Module/715. Range Module_test.go | leetcode/0715.Range-Module/715. Range Module_test.go | package leetcode
import (
"fmt"
"testing"
)
func Test_Problem715(t *testing.T) {
obj := Constructor715()
obj.AddRange(10, 20)
obj.RemoveRange(14, 16)
fmt.Printf("query = %v\n", obj.QueryRange(10, 14)) // returns true
fmt.Printf("query = %v\n", obj.QueryRange(13, 15)) // returns false
fmt.Printf("query = %... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0715.Range-Module/715. Range Module.go | leetcode/0715.Range-Module/715. Range Module.go | package leetcode
// RangeModule define
type RangeModule struct {
Root *SegmentTreeNode
}
// SegmentTreeNode define
type SegmentTreeNode struct {
Start, End int
Tracked bool
Lazy int
Left, Right *SegmentTreeNode
}
// Constructor715 define
func Constructor715() RangeModule {
return RangeModule{&Segme... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree/235. Lowest Common Ancestor of a Binary Search Tree_test.go | leetcode/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree/235. Lowest Common Ancestor of a Binary Search Tree_test.go | package leetcode
import (
"fmt"
"testing"
"github.com/halfrost/LeetCode-Go/structures"
)
type question235 struct {
para235
ans235
}
// para 是参数
// one 代表第一个参数
type para235 struct {
one []int
two []int
thr []int
}
// ans 是答案
// one 代表第一个答案
type ans235 struct {
one []int
}
func Test_Problem235(t *testing.T... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree/235. Lowest Common Ancestor of a Binary Search Tree.go | leetcode/0235.Lowest-Common-Ancestor-of-a-Binary-Search-Tree/235. Lowest Common Ancestor of 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 lowestCommonAncestor(root, p, q *TreeNode) *T... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0155.Min-Stack/155. Min Stack.go | leetcode/0155.Min-Stack/155. Min Stack.go | package leetcode
// MinStack define
type MinStack struct {
elements, min []int
l int
}
/** initialize your data structure here. */
// Constructor155 define
func Constructor155() MinStack {
return MinStack{make([]int, 0), make([]int, 0), 0}
}
// Push define
func (this *MinStack) Push(x int) {
this.el... | go | MIT | d78a9e0927a302038992428433d2eb450efd93a2 | 2026-01-07T08:36:06.754118Z | false |
halfrost/LeetCode-Go | https://github.com/halfrost/LeetCode-Go/blob/d78a9e0927a302038992428433d2eb450efd93a2/leetcode/0155.Min-Stack/155. Min Stack_test.go | leetcode/0155.Min-Stack/155. Min Stack_test.go | package leetcode
import (
"fmt"
"testing"
)
func Test_Problem155(t *testing.T) {
obj1 := Constructor155()
obj1.Push(1)
fmt.Printf("obj1 = %v\n", obj1)
obj1.Push(0)
fmt.Printf("obj1 = %v\n", obj1)
obj1.Push(10)
fmt.Printf("obj1 = %v\n", obj1)
obj1.Pop()
fmt.Printf("obj1 = %v\n", obj1)
param3 := obj1.Top()
... | 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.