Categorygithub.com/NothingXiang/algo
repositorypackage
0.0.0-20241108025837-c3b41df9d085
Repository: https://github.com/nothingxiang/algo.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

algo

Algorithm learning

Directory:

.
├── README.md
├── go.mod
├── go.sum
├── leetcode
│ ├── array
│ │ ├── duplicate.go
│ │ ├── easy.go
│ │ ├── intersection.go
│ │ ├── max_profit.go
│ │ ├── move_in_situ.go
│ │ ├── summaryRanges.go
│ │ ├── summaryRanges_test.go
│ │ ├── validMountainArray.go
│ │ └── validMountainArray_test.go
│ ├── dp
│ │ ├── climbStairs.go
│ │ └── maxSubArray.go
│ ├── editor
│ │ └── cn
│ │     ├── 1_two-sum.go
│ │     ├── 209_minimum-size-subarray-sum.go
│ │     ├── 209_minimum-size-subarray-sum_test.go
│ │     ├── 242_valid-anagram.go
│ │     ├── 242_valid-anagram_test.go
│ │     ├── 27_remove-element.go
│ │     ├── 27_remove-element_test.go
│ │     ├── 704_binary-search.go
│ │     ├── 704_binary-search_test.go
│ │     ├── 977_squares-of-a-sorted-array.go
│ │     ├── 977_squares-of-a-sorted-array_test.go
│ │     └── doc
│ │         ├── content
│ │         │ ├── 209_minimum-size-subarray-sum.md
│ │         │ ├── 242_valid-anagram.md
│ │         │ ├── 27_remove-element.md
│ │         │ ├── 704_binary-search.md
│ │         │ ├── 977_squares-of-a-sorted-array.md
│ │         │ ├── [121]best-time-to-buy-and-sell-stock.md
│ │         │ ├── [1]two-sum.md
│ │         │ ├── [206]reverse-linked-list.md
│ │         │ ├── [21]merge-two-sorted-lists.md
│ │         │ └── [704]binary-search.md
│ │         ├── note
│ │         └── solution
│ ├── list
│ │ ├── deleteDuplicates.go
│ │ ├── deleteDuplicates_test.go
│ │ ├── list_node.go
│ │ ├── list_node_test.go
│ │ ├── reversePrint.go
│ │ └── reversePrint_test.go
│ ├── listnode.go
│ ├── recursion
│ │ ├── isPowe.go
│ │ └── isPowe_test.go
│ ├── stack.go
│ ├── string
│ │ ├── addBinary.go
│ │ ├── addBinary_test.go
│ │ ├── canConstruct.go
│ │ ├── canConstruct_test.go
│ │ ├── findTheDifference.go
│ │ ├── findTheDifference_test.go
│ │ ├── firstUniqChar.go
│ │ ├── firstUniqChar_test.go
│ │ ├── lengthOfLastWord.go
│ │ ├── lengthOfLastWord_test.go
│ │ ├── longestCommonPrefix.go
│ │ ├── longestCommonPrefix_test.go
│ │ ├── reverseVowels.go
│ │ ├── reverseVowels_test.go
│ │ ├── romanToInt.go
│ │ ├── strStr.go
│ │ ├── strStr_test.go
│ │ └── string_test.go
│ └── tree
│     ├── hasPathSum.go
│     ├── isSameTree.go
│     ├── isSubtree.go
│     ├── isSymmetric.go
│     ├── maxDepth.go
│     ├── maxPathSum.go
│     ├── minDepth.go
│     └── treenode.go
└── main.go

14 directories, 72 files

ref: https://github.com/youngyangyang04/leetcode-master?tab=readme-ov-file

常用操作

取数值各个位上的单数

func IterDigest(n int, do func(digest int)) {
	for n != 0 {
		do(n % 10)
		n /= 10
	}
}

例如,取数值各个位上的单数之和:

func getSum(n int) (sum int) {
	iterDigest(n, func(digest int) {
		sum += digest * digest
	})
	return
}