Documentation
¶
Index ¶
- Constants
- func Atoi(s string) int
- func AtoiX(s string) int
- func BinarySearchX(nums []int, target int) int
- func CombinationSum(candidates []int, target int) [][]int
- func CombinationSumX(candidates []int, target int) [][]int
- func CountPrimes(n int) int
- func DigitCounts(k int, n int) int
- func FindBadVersion(n int) int
- func FindPeak(A []int) int
- func FizzBuzz(n int) []string
- func HashCode(key string, HashSize int) int
- func InOrder(root *TreeNode, res *[]int, k1 int, k2 int)
- func IsBadVersion(n int) bool
- func IsOpr(s string) bool
- func IsPrime(n int) bool
- func KetLargestElementX(n int, nums []int) int
- func KthLargestElement(n int, nums []int) int
- func LongestWord(m []string) []string
- func Lss(a, b string) int
- func MergeArrayX(a, b []int) []int
- func MergeSortedArray(a, b []int) []int
- func Nice(s int) int
- func PartitionArray(nums []int, k int) int
- func Permute(nums []int) [][]int
- func PreOrder(root *TreeNode, res *[]int)
- func PreOrderTravelSal(root *TreeNode) []int
- func Rehashing()
- func RotateString(str *string, offset int)
- func SearchMatrix(matrix [][]int, target int) bool
- func SortLetters(st string) string
- func StrDeleteCh(str string, ch int32) string
- func StrReplaceCh(str string, ch1, ch2 int32) string
- func StrStr(source, target string) int
- func TrailingZeros(n int64) int64
- func TrailingZerosX(n int64) int64
- func TwoSum(a []int, m int) []int
- func TwoSumSlow(a []int, m int) []int
- func UglyNumber(n int) int
- type LinkNode
- type TreeNode
Constants ¶
View Source
const INT_MAX = 1<<31 - 1
View Source
const INT_MIN = -(1 << 31)
Variables ¶
This section is empty.
Functions ¶
func BinarySearchX ¶
func CombinationSum ¶
func CombinationSumX ¶
func CountPrimes ¶
func DigitCounts ¶
func FindBadVersion ¶
func FizzBuzz ¶
给你一个整数n. 从 1 到 n 按照下面的规则打印每个数:
如果这个数被3整除,打印fizz. 如果这个数被5整除,打印buzz. 如果这个数能同时被3和5整除,打印fizz buzz. 如果这个数既不能被 3 整除也不能被 5 整除,打印数字本身。 Example 比如 n = 15, 返回一个字符串数组:
[
"1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11", "fizz", "13", "14", "fizz buzz"
] Challenge 你是否可以只用一个 if 来实现
func IsBadVersion ¶
func KthLargestElement ¶
O(n+mlogm) 超时,但是不稳定,最差的是O(n^2)
func LongestWord ¶
func Lss ¶
dp[i][j]表示A串匹配到i,B串匹配到j时的最大公共长度
dp[i][j]=dp[i-1][j-1]+1 ,A[i]==B[j] dp[i][j]=0 ,A[i]!=B[j]
func MergeArrayX ¶
func PartitionArray ¶
func PreOrderTravelSal ¶
func RotateString ¶
func SearchMatrix ¶
func SortLetters ¶
func StrDeleteCh ¶
func StrReplaceCh ¶
func TrailingZerosX ¶
原理: $$ f(n)=[\farc{n!}{5}] + [\farc{n!}{5^2}] +\cdots + [\farc{n!}{5^n}] $$ $$ q_0 = n q_{i+1} = [\farc{q_i}{5}] $$ $$ q_{i+1} = 0 <==> 5^{k+1} > n $$
for q != 0 { q /= 5 // ==> a1 + a2 + ... + an res += q }
func UglyNumber ¶
设计一个算法,找出只含素因子2,3,5 的第 n 小的数。
符合条件的数如:1, 2, 3, 4, 5, 6, 8, 9, 10, 12...
Example 样例 1:
输入:9 输出:10 样例 2:
输入:1 输出:1 Challenge 要求时间复杂度为 O(nlogn) 或者 O(n)。
Notice 我们可以认为 1 也是一个丑数。
Types ¶
Source Files
¶
- 02-trailingzeros.go
- 03-digitcounts.go
- 04-uglynumber.go
- 05-kthlargestelement.go
- 06-mergeSortedArray.go
- 08-rotateString.go
- 09-fizzbuzz.go
- 11-searchRange.go
- 128-hashcode.go
- 129-rehashing.go
- 13-strStr.go
- 1324-CountPrimes.go
- 133-longestword.go
- 135-combinationsum.go
- 14-binarysearch.go
- 15-permute.go
- 28-searchMatrix.go
- 29-partitionArray.go
- 35-reverse.go
- 368-evaluateExpression.go
- 49-sortLetters.go
- 54-atoi.go
- 56-Twosum.go
- 66-preordertravelsal.go
- 74-findbandversion.go
- 75-FIndPeekElement.go
- 79-longestcommonSubstring.go
Click to show internal directories.
Click to hide internal directories.