chore: add package level comments

This commit is contained in:
Yiyang Kang 2026-02-27 12:55:48 +09:00
parent cc87c4b30c
commit ee1868a10e
Signed by: kkyy
SSH key fingerprint: SHA256:lJSbAzC3MvrSORdvIVK6h/3g+rVKJNzM7zq0MgA9WKY
303 changed files with 303 additions and 0 deletions

View file

@ -1,3 +1,4 @@
// Package q1 implements a solution for https://leetcode.com/problems/two-sum/
package q1
import "slices"

View file

@ -1,3 +1,4 @@
// Package q12 implements a solution for https://leetcode.com/problems/integer-to-roman/
package q12
import "strings"

View file

@ -1,3 +1,4 @@
// Package q13 implements a solution for https://leetcode.com/problems/roman-to-integer/
package q13
func lookup(b byte) int {

View file

@ -1,3 +1,4 @@
// Package q14 implements a solution for https://leetcode.com/problems/longest-common-prefix/
package q14
func longestCommonPrefix(strs []string) string {

View file

@ -1,3 +1,4 @@
// Package q15 implements a solution for https://leetcode.com/problems/3sum/
package q15
import "slices"

View file

@ -1,3 +1,4 @@
// Package q17 implements a solution for https://leetcode.com/problems/letter-combinations-of-a-phone-number/
package q17
var alphabets = [][]byte{

View file

@ -1,3 +1,4 @@
// Package q19 implements a solution for https://leetcode.com/problems/remove-nth-node-from-end-of-list/
package q19
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q2 implements a solution for https://leetcode.com/problems/add-two-numbers/
package q2
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q20 implements a solution for https://leetcode.com/problems/valid-parentheses/
package q20
func isValid(s string) bool {

View file

@ -1,3 +1,4 @@
// Package q21 implements a solution for https://leetcode.com/problems/merge-two-sorted-lists/
package q21
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q22 implements a solution for https://leetcode.com/problems/generate-parentheses/
package q22
func gen(n, lvl, used int, buf []byte, ret []string) []string {

View file

@ -1,3 +1,4 @@
// Package q23 implements a solution for https://leetcode.com/problems/merge-k-sorted-lists/
package q23
import "container/heap"

View file

@ -1,3 +1,4 @@
// Package q25 implements a solution for https://leetcode.com/problems/reverse-nodes-in-k-group/
package q25
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q28 implements a solution for https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/
package q28
import "strings"

View file

@ -1,3 +1,4 @@
// Package q3 implements a solution for https://leetcode.com/problems/longest-substring-without-repeating-characters/
package q3
func lengthOfLongestSubstring(s string) int {

View file

@ -1,3 +1,4 @@
// Package q33 implements a solution for https://leetcode.com/problems/search-in-rotated-sorted-array/
package q33
func findK(nums []int) int {

View file

@ -1,3 +1,4 @@
// Package q34 implements a solution for https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/
package q34
func find(nums []int, target int) int {

View file

@ -1,3 +1,4 @@
// Package q35 implements a solution for https://leetcode.com/problems/search-insert-position/
package q35
func searchInsert(nums []int, target int) int {

View file

@ -1,3 +1,4 @@
// Package q36 implements a solution for https://leetcode.com/problems/valid-sudoku/
package q36
func validateCol(board [][]byte, col int) bool {

View file

@ -1,3 +1,4 @@
// Package q39 implements a solution for https://leetcode.com/problems/combination-sum/
package q39
import "slices"

View file

@ -1,3 +1,4 @@
// Package q4 implements a solution for https://leetcode.com/problems/median-of-two-sorted-arrays/
package q4
import "math"

View file

@ -1,3 +1,4 @@
// Package q42 implements a solution for https://leetcode.com/problems/trapping-rain-water/
package q42
func trap(height []int) int {

View file

@ -1,3 +1,4 @@
// Package q43 implements a solution for https://leetcode.com/problems/multiply-strings/
package q43
import "slices"

View file

@ -1,3 +1,4 @@
// Package q46 implements a solution for https://leetcode.com/problems/permutations/
package q46
func recurse(nums []int, offset int, buf []int, seen []bool, ret [][]int) [][]int {

View file

@ -1,3 +1,4 @@
// Package q48 implements a solution for https://leetcode.com/problems/rotate-image/
package q48
func rotateCell(matrix [][]int, x, y int) {

View file

@ -1,3 +1,4 @@
// Package q49 implements a solution for https://leetcode.com/problems/group-anagrams/
package q49
import "slices"

View file

@ -1,3 +1,4 @@
// Package q5 implements a solution for https://leetcode.com/problems/longest-palindromic-substring/
package q5
// Note: Although it can be done in O(N) with, e.g., Manacher's algorithm, the

View file

@ -1,3 +1,4 @@
// Package q50 implements a solution for https://leetcode.com/problems/powx-n/
package q50
func myPow(x float64, n int) float64 {

View file

@ -1,3 +1,4 @@
// Package q52 implements a solution for https://leetcode.com/problems/n-queens-ii/
package q52
func findNSolutions(nQueen, row int, rows, cols, diag1, diag2 []bool) int {

View file

@ -1,3 +1,4 @@
// Package q53 implements a solution for https://leetcode.com/problems/maximum-subarray/
package q53
import "math"

View file

@ -1,3 +1,4 @@
// Package q54 implements a solution for https://leetcode.com/problems/spiral-matrix/
package q54
import "math"

View file

@ -1,3 +1,4 @@
// Package q56 implements a solution for https://leetcode.com/problems/merge-intervals/
package q56
import "slices"

View file

@ -1,3 +1,4 @@
// Package q57 implements a solution for https://leetcode.com/problems/insert-interval/
package q57
func insert(intervals [][]int, newInterval []int) [][]int {

View file

@ -1,3 +1,4 @@
// Package q58 implements a solution for https://leetcode.com/problems/length-of-last-word/
package q58
func lengthOfLastWord(s string) int {

View file

@ -1,3 +1,4 @@
// Package q6 implements a solution for https://leetcode.com/problems/zigzag-conversion/
package q6
import "strings"

View file

@ -1,3 +1,4 @@
// Package q61 implements a solution for https://leetcode.com/problems/rotate-list/
package q61
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q62 implements a solution for https://leetcode.com/problems/unique-paths/
package q62
func uniquePaths(m int, n int) int {

View file

@ -1,3 +1,4 @@
// Package q63 implements a solution for https://leetcode.com/problems/unique-paths-ii/
package q63
func uniquePathsWithObstacles(obstacleGrid [][]int) int {

View file

@ -1,3 +1,4 @@
// Package q64 implements a solution for https://leetcode.com/problems/minimum-path-sum/
package q64
func minPathSum(grid [][]int) int {

View file

@ -1,3 +1,4 @@
// Package q66 implements a solution for https://leetcode.com/problems/plus-one/
package q66
func plusOne(digits []int) []int {

View file

@ -1,3 +1,4 @@
// Package q67 implements a solution for https://leetcode.com/problems/add-binary/
package q67
func toDigit(byt byte) uint8 { return byt - '0' }

View file

@ -1,3 +1,4 @@
// Package q68 implements a solution for https://leetcode.com/problems/text-justification/
package q68
var (

View file

@ -1,3 +1,4 @@
// Package q69 implements a solution for https://leetcode.com/problems/sqrtx/
package q69
func mySqrt(x int) int {

View file

@ -1,3 +1,4 @@
// Package q70 implements a solution for https://leetcode.com/problems/climbing-stairs/
package q70
func nWays(n, i int, cache []int) int {

View file

@ -1,3 +1,4 @@
// Package q71 implements a solution for https://leetcode.com/problems/simplify-path/
package q71
import "strings"

View file

@ -1,3 +1,4 @@
// Package q72 implements a solution for https://leetcode.com/problems/edit-distance/
package q72
func make2d[T any](rows, cols int) [][]T {

View file

@ -1,3 +1,4 @@
// Package q73 implements a solution for https://leetcode.com/problems/set-matrix-zeroes/
package q73
func setZeroes(matrix [][]int) {

View file

@ -1,3 +1,4 @@
// Package q74 implements a solution for https://leetcode.com/problems/search-a-2d-matrix/
package q74
func searchMatrix(matrix [][]int, target int) bool {

View file

@ -1,3 +1,4 @@
// Package q77 implements a solution for https://leetcode.com/problems/combinations/
package q77
var (

View file

@ -1,3 +1,4 @@
// Package q79 implements a solution for https://leetcode.com/problems/word-search/
package q79
func search(board [][]byte, word string, prefixLen, row, col int) bool {

View file

@ -1,3 +1,4 @@
// Package q8 implements a solution for https://leetcode.com/problems/string-to-integer-atoi/
package q8
const (

View file

@ -1,3 +1,4 @@
// Package q82 implements a solution for https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/
package q82
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q84 implements a solution for https://leetcode.com/problems/largest-rectangle-in-histogram/
package q84
func largestRectangleArea(heights []int) int {

View file

@ -1,3 +1,4 @@
// Package q85 implements a solution for https://leetcode.com/problems/maximal-rectangle/
package q85
func maximalRectangle(matrix [][]byte) int {

View file

@ -1,3 +1,4 @@
// Package q86 implements a solution for https://leetcode.com/problems/partition-list/
package q86
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q9 implements a solution for https://leetcode.com/problems/palindrome-number/
package q9
import "strconv"

View file

@ -1,3 +1,4 @@
// Package q92 implements a solution for https://leetcode.com/problems/reverse-linked-list-ii/
package q92
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q94 implements a solution for https://leetcode.com/problems/binary-tree-inorder-traversal/
package q94
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q97 implements a solution for https://leetcode.com/problems/interleaving-string/
package q97
func isInterleave(s1 string, s2 string, s3 string) bool {

View file

@ -1,3 +1,4 @@
// Package q98 implements a solution for https://leetcode.com/problems/validate-binary-search-tree/
package q98
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q100 implements a solution for https://leetcode.com/problems/same-tree/
package q100
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q101 implements a solution for https://leetcode.com/problems/symmetric-tree/
package q101
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q102 implements a solution for https://leetcode.com/problems/binary-tree-level-order-traversal/
package q102
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q103 implements a solution for https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/
package q103
import "slices"

View file

@ -1,3 +1,4 @@
// Package q104 implements a solution for https://leetcode.com/problems/maximum-depth-of-binary-tree/
package q104
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q105 implements a solution for https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
package q105
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q106 implements a solution for https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/
package q106
import "slices"

View file

@ -1,3 +1,4 @@
// Package q108 implements a solution for https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
package q108
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q110 implements a solution for https://leetcode.com/problems/balanced-binary-tree/
package q110
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q112 implements a solution for https://leetcode.com/problems/path-sum/
package q112
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q114 implements a solution for https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
package q114
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q117 implements a solution for https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/
package q117
type Node struct {

View file

@ -1,3 +1,4 @@
// Package q118 implements a solution for https://leetcode.com/problems/pascals-triangle/
package q118
func generate(numRows int) [][]int {

View file

@ -1,3 +1,4 @@
// Package q120 implements a solution for https://leetcode.com/problems/triangle/
package q120
func minimumTotal(triangle [][]int) int {

View file

@ -1,3 +1,4 @@
// Package q125 implements a solution for https://leetcode.com/problems/valid-palindrome/
package q125
func isAlphanumeric(c byte) bool {

View file

@ -1,3 +1,4 @@
// Package q127 implements a solution for https://leetcode.com/problems/word-ladder/
package q127
// Ideas for improvement: use a hashmap to index strings instead of an O(n^2)

View file

@ -1,3 +1,4 @@
// Package q128 implements a solution for https://leetcode.com/problems/longest-consecutive-sequence/
package q128
func longestConsecutive(nums []int) int {

View file

@ -1,3 +1,4 @@
// Package q129 implements a solution for https://leetcode.com/problems/sum-root-to-leaf-numbers/
package q129
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q130 implements a solution for https://leetcode.com/problems/surrounded-regions/
package q130
func markI(board [][]byte, x, y int) {

View file

@ -1,3 +1,4 @@
// Package q133 implements a solution for https://leetcode.com/problems/clone-graph/
package q133
type Node struct {

View file

@ -1,3 +1,4 @@
// Package q134 implements a solution for https://leetcode.com/problems/gas-station/
package q134
func canCompleteCircuit(gas []int, cost []int) int {

View file

@ -1,3 +1,4 @@
// Package q135 implements a solution for https://leetcode.com/problems/candy/
package q135
func candy(ratings []int) int {

View file

@ -1,3 +1,4 @@
// Package q136 implements a solution for https://leetcode.com/problems/single-number/
package q136
func singleNumber(nums []int) int {

View file

@ -1,3 +1,4 @@
// Package q137 implements a solution for https://leetcode.com/problems/single-number-ii/
package q137
func singleNumber(nums []int) int {

View file

@ -1,3 +1,4 @@
// Package q138 implements a solution for https://leetcode.com/problems/copy-list-with-random-pointer/
package q138
type Node struct {

View file

@ -1,3 +1,4 @@
// Package q139 implements a solution for https://leetcode.com/problems/word-break/
package q139
func wordBreak(s string, wordDict []string) bool {

View file

@ -1,3 +1,4 @@
// Package q141 implements a solution for https://leetcode.com/problems/linked-list-cycle/
package q141
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q142 implements a solution for https://leetcode.com/problems/linked-list-cycle-ii/
package q142
type ListNode struct {

View file

@ -1,3 +1,4 @@
// Package q144 implements a solution for https://leetcode.com/problems/binary-tree-preorder-traversal/
package q144
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q145 implements a solution for https://leetcode.com/problems/binary-tree-postorder-traversal/
package q145
type TreeNode struct {

View file

@ -1,3 +1,4 @@
// Package q146 implements a solution for https://leetcode.com/problems/lru-cache/
package q146
type lruNode struct {

View file

@ -1,3 +1,4 @@
// Package q148 implements a solution for https://leetcode.com/problems/sort-list/
package q148
import "slices"

View file

@ -1,3 +1,4 @@
// Package q150 implements a solution for https://leetcode.com/problems/evaluate-reverse-polish-notation/
package q150
import "strconv"

View file

@ -1,3 +1,4 @@
// Package q151 implements a solution for https://leetcode.com/problems/reverse-words-in-a-string/
package q151
import "strings"

View file

@ -1,3 +1,4 @@
// Package q153 implements a solution for https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/
package q153
func findMin(nums []int) int {

View file

@ -1,3 +1,4 @@
// Package q155 implements a solution for https://leetcode.com/problems/min-stack/
package q155
type stackElem struct {

View file

@ -1,3 +1,4 @@
// Package q162 implements a solution for https://leetcode.com/problems/find-peak-element/
package q162
// Important constraint: nums[i] != nums[i + 1]

View file

@ -1,3 +1,4 @@
// Package q167 implements a solution for https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/
package q167
func twoSum(numbers []int, target int) []int {

View file

@ -1,3 +1,4 @@
// Package q172 implements a solution for https://leetcode.com/problems/factorial-trailing-zeroes/
package q172
// Note: actually, counting 5 alone is enough since 2 certainly occurs more than 5.

View file

@ -1,3 +1,4 @@
// Package q173 implements a solution for https://leetcode.com/problems/binary-search-tree-iterator/
package q173
type TreeNode struct {

Some files were not shown because too many files have changed in this diff Show more