lintcode

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

	"love",
	"hate",
	"yes"
	}
输出: ["like", "love", "hate"]

### **Challenge**

遍历两次的办法很容易想到,如果只遍历一次你有没有什么好办法?
[传送门](./133-longestword.go)
## 135-combinationsum

### **Description**

中文English

给定一个候选数字的集合 `candidates` 和一个目标值 `target`. 找到 `candidates` 中所有的和为 `target` 的组合.

在同一个组合中, `candidates` 中的某个数字不限次数地出现.

所有数值 (包括 `target` ) 都是正整数.返回的每一个组合内的数字必须是非降序的.返回的所有组合之间可以是任意顺序.解集不能包含重复的组合.


### **Example**

**样例 1:**

输入: candidates = [2, 3, 6, 7], target = 7 输出: [[7], [2, 2, 3]]


**样例 2:**

输入: candidates = [1], target = 3 输出: [[1, 1, 1]]

[传送门](./135-combinationsum.go)
## 1324-countprimes

```cgo
计算小于非负数n的质数的个数。

Example
样例 1

输入: n = 2
输出: 0
样例 2

输入: n = 4
输出: 2
解析:2, 3 是素数

传送门

Documentation

Index

Constants

View Source
const INT_MAX = 1<<31 - 1
View Source
const INT_MIN = -(1 << 31)

Variables

This section is empty.

Functions

func Atoi

func Atoi(s string) int

func AtoiX

func AtoiX(s string) int

func BinarySearchX

func BinarySearchX(nums []int, target int) int

func CombinationSum

func CombinationSum(candidates []int, target int) [][]int

func CombinationSumX

func CombinationSumX(candidates []int, target int) [][]int

func CountPrimes

func CountPrimes(n int) int

func DigitCounts

func DigitCounts(k int, n int) int

func FindBadVersion

func FindBadVersion(n int) int

func FindPeak

func FindPeak(A []int) int

func FizzBuzz

func FizzBuzz(n int) []string

给你一个整数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 HashCode

func HashCode(key string, HashSize int) int

func InOrder

func InOrder(root *TreeNode, res *[]int, k1 int, k2 int)

左子树 ---> 根结点 ---> 右子树 BFS

func IsBadVersion

func IsBadVersion(n int) bool

func IsOpr

func IsOpr(s string) bool

func IsPrime

func IsPrime(n int) bool

func KetLargestElementX

func KetLargestElementX(n int, nums []int) int

O(nlogn) 稳定

func KthLargestElement

func KthLargestElement(n int, nums []int) int

O(n+mlogm) 超时,但是不稳定,最差的是O(n^2)

func LongestWord

func LongestWord(m []string) []string

func Lss

func Lss(a, b string) int

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 MergeArrayX(a, b []int) []int

func MergeSortedArray

func MergeSortedArray(a, b []int) []int

a,b必须已经是排序的的

func Nice

func Nice(s int) int

func PartitionArray

func PartitionArray(nums []int, k int) int

func Permute

func Permute(nums []int) [][]int

func PreOrder

func PreOrder(root *TreeNode, res *[]int)

func PreOrderTravelSal

func PreOrderTravelSal(root *TreeNode) []int

func Rehashing

func Rehashing()

func RotateString

func RotateString(str *string, offset int)

func SearchMatrix

func SearchMatrix(matrix [][]int, target int) bool

func SortLetters

func SortLetters(st string) string

func StrDeleteCh

func StrDeleteCh(str string, ch int32) string

func StrReplaceCh

func StrReplaceCh(str string, ch1, ch2 int32) string

func StrStr

func StrStr(source, target string) int

func TrailingZeros

func TrailingZeros(n int64) int64

超时

func TrailingZerosX

func TrailingZerosX(n int64) int64

原理: $$ 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 TwoSum

func TwoSum(a []int, m int) []int

O(N)

func TwoSumSlow

func TwoSumSlow(a []int, m int) []int

O(N^2)

func UglyNumber

func UglyNumber(n int) int

设计一个算法,找出只含素因子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

type LinkNode

type LinkNode struct {
	Val  int
	Next *LinkNode
}
func ReverseLink(l *LinkNode) *LinkNode

func ReverseLinkX

func ReverseLinkX(l *LinkNode) *LinkNode

type TreeNode

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func NewTravelSal

func NewTravelSal() *TreeNode

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL