leetcode

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanMeasureWater

func CanMeasureWater(x, y, z int) bool

1. 数学方法(贝祖定理) 贝祖定理:对应给定的正整数a, b, 方程a*x + b*y = c有解的充要条件为c是gcd(a,b)的整数倍

func CanPartition

func CanPartition(nums []int) bool

func ClimbStairs

func ClimbStairs(n int) int

solution 1

func ClimbStairsDP

func ClimbStairsDP(n int) int

solution 2: dp

func CombinationSum

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

func CombinationSumII

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

func Combine

func Combine(n, k int) [][]int

func ContainsNearbyAlmostDuplicate

func ContainsNearbyAlmostDuplicate(nums []int, k, t int) bool

func ContainsNearbyDuplicate

func ContainsNearbyDuplicate(nums []int, k int) bool

func DeleteNode

func DeleteNode(node *ListNode)

func FindSubstring

func FindSubstring(s string, words []string) []int

TODO

func FourSum

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

func HasPathSum

func HasPathSum(root *TreeNode, sum int) bool

func Int2Roman

func Int2Roman(num int) string

func IntegerBreak

func IntegerBreak(n int) int

func InterSection

func InterSection(num1, num2 []int) []int

func IsAnagram

func IsAnagram(s string, t string) bool

func IsMatch

func IsMatch(target, pattern string) bool

target, input string pattern, pattern string

func IsPowerOfTwo

func IsPowerOfTwo(n int) bool

func IsSubtree1

func IsSubtree1(s *TreeNode, t *TreeNode) bool

DFS暴力匹配

func IsSymmetric

func IsSymmetric(root *TreeNode) bool

func IsValidParentheses

func IsValidParentheses(s string) bool

func IsValidSudoku

func IsValidSudoku(board [][]int) bool

func Knapsack01

func Knapsack01(w, v []int, c int) int

func Knapsack01DP

func Knapsack01DP(w, v []int, c int) int

思路2:动态规划 自下而上

func LadderLength

func LadderLength(beginWord, endWord string, wordList []string) int

func LenghtOfLISWithBin

func LenghtOfLISWithBin(nums []int) int

binary search

func LengthOfLISDPReview

func LengthOfLISDPReview(nums []int) int

func LengthOfLISWithDP

func LengthOfLISWithDP(nums []int) int

dp

func LengthOfLongestSubstring

func LengthOfLongestSubstring(s string) int

func LengthOfLongestSubstringReview

func LengthOfLongestSubstringReview(s string) int

func LengthOfLongestSubstringReview2

func LengthOfLongestSubstringReview2(s string) int

func LengthOfLongestSubstringTwoDistinct

func LengthOfLongestSubstringTwoDistinct(s string) int

TODO

func LetterCombinations

func LetterCombinations(digits string) []string

func LevelOrder

func LevelOrder(root *TreeNode) [][]int

func LevelOrderBottom

func LevelOrderBottom(root *TreeNode) [][]int

func MaxArea

func MaxArea(height []int) int

11. 盛最多水的容器 双指针

func MaxDepth

func MaxDepth(root *TreeNode) int

func MaxSubArrayDC

func MaxSubArrayDC(nums []int) int

1. Divide-and-Conquer 使用分治法解决问题的典型例子。分治法解决问题的模板:

a) 定义基本情况
b) 将问题分解为子问题并 递归 地解决它们
c) 合并子问题的解以获得原始问题的解

func MaxSubArrayDP

func MaxSubArrayDP(nums []int) int

3. Dynamic Program

func MaxSubArrayGreedy

func MaxSubArrayGreedy(nums []int) int

2.

func MaximalSquare

func MaximalSquare(matrix [][]byte) int

1. 暴力遍历每一个元素,作为正方形的左上角元素(略) 2. DP

func MaximalSquare2

func MaximalSquare2(matrix [][]byte) int

func MinDepth

func MinDepth(root *TreeNode) int

func MinSubArrayLen

func MinSubArrayLen(s int, nums []int) int

func MinWindow

func MinWindow(s, t string) string

TODO 双指针/滑动窗口

func MinimumTotal

func MinimumTotal(triangle [][]int) int

func MoveZeros

func MoveZeros(nums []int) []int

思路:

  1. 最简单的解法 使用辅助空间,把非零元素copy到辅助空间。时间复杂度O(n),空间复杂度O(n)
  2. 在原数组中操作 使用辅助索引k,k指向第一个零元素,循环扫描数组nums,遇到非零元素和k交换位置

func Multiply

func Multiply(num1, num2 string) string

func MySqrt1

func MySqrt1(x int) int

1. 袖珍计算器算法

func NumSquares

func NumSquares(n int) int

func NumTreesViaCatalan

func NumTreesViaCatalan(n int) int

2. Deduction 卡特兰数(Catalan)

func NumTreesViaDP

func NumTreesViaDP(n int) int

1. DP

func NumberIslands

func NumberIslands(grid [][]byte) int

func Permute

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

func PermuteUnique

func PermuteUnique(nums []int) [][]int

func PreorderTraversal

func PreorderTraversal(root *TreeNode) []int

func PrintList

func PrintList(head *ListNode)

func PrintTree

func PrintTree(root *TreeNode)

func RecordList

func RecordList(head *ListNode)

func RestoreIpAddress

func RestoreIpAddress(s string) []string

func Rob

func Rob(nums []int) int

func SingleNumber

func SingleNumber(nums []int) int

func SingleNumberII

func SingleNumberII(nums []int) int

func SingleNumberIII

func SingleNumberIII(nums []int) []int

260. Single Number III 给定一个整数数组 nums,其中恰好有两个元素只出现一次,其余所有元素均出现两次。 找出只出现一次的那两个元素。 方便描述,假设这两个元素为a,b

func SolveNQueens

func SolveNQueens(n int) [][]string

func SortColorReview

func SortColorReview(nums []int)

review

func SortColors

func SortColors(nums []int)

三指针 重点在处理边界问题

func SpiralOrder

func SpiralOrder(matrix [][]int) []int

func SuperEggDrop

func SuperEggDrop(k, n int) int

状态转移方程 dp(k, n) =

func ThreeSum

func ThreeSum(nums []int) [][]int

三数之和等于0的所有

func TopKFrequent

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

=========================

func TopKFrequentHeap

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

使用堆改进

func TopKFrequentHeapReview

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

func TwoSum

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

func TwoSumII

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

func WordSearch

func WordSearch(board [][]byte, word string) bool

Types

type ListHeap

type ListHeap []*ListNode

func (ListHeap) Len

func (lh ListHeap) Len() int

func (ListHeap) Less

func (lh ListHeap) Less(i, j int) bool

func (*ListHeap) Pop

func (lh *ListHeap) Pop() interface{}

func (*ListHeap) Push

func (lh *ListHeap) Push(node interface{})

func (ListHeap) Swap

func (lh ListHeap) Swap(i, j int)

type ListNode

type ListNode struct {
	Val  int
	Next *ListNode
}

*

  • Definition for singly-linked list.
  • type ListNode struct {
  • Val int
  • Next *ListNode
  • }

func BuildList

func BuildList(elements []int) *ListNode

func MergeKLists

func MergeKLists(lists []*ListNode) *ListNode

func NewListNode

func NewListNode(val int) *ListNode

func RemoveElements

func RemoveElements(head *ListNode, val int) *ListNode

func RemoveNthFromEnd

func RemoveNthFromEnd(head *ListNode, n int) *ListNode

func ReverseBetween

func ReverseBetween(head *ListNode, m, n int) *ListNode

func ReverseLinkedListIter

func ReverseLinkedListIter(head *ListNode) *ListNode

func ReverseList

func ReverseList(head *ListNode) *ListNode

func RotateRight

func RotateRight(head *ListNode, k int) *ListNode

type NestedInteger

type NestedInteger struct {
	// contains filtered or unexported fields
}

++++++++++++++++++ TODO

func (*NestedInteger) Add

func (ni *NestedInteger) Add(elem NestedInteger)

func (*NestedInteger) GetInteger

func (ni *NestedInteger) GetInteger() int

func (*NestedInteger) IsInteger

func (ni *NestedInteger) IsInteger() bool

type NestedIterator

type NestedIterator struct {
	// contains filtered or unexported fields
}

func Construct

func Construct(nestedList []*NestedInteger) *NestedIterator

func (*NestedIterator) HasNext

func (this *NestedIterator) HasNext() bool

func (*NestedIterator) Next

func (this *NestedIterator) Next() int

type Node

type Node struct {
	// contains filtered or unexported fields
}

type NodeHeap

type NodeHeap []*Node

func (NodeHeap) Len

func (h NodeHeap) Len() int

func (NodeHeap) Less

func (h NodeHeap) Less(i, j int) bool

控制大根堆/小根堆

func (*NodeHeap) Pop

func (h *NodeHeap) Pop() interface{}

func (*NodeHeap) Push

func (h *NodeHeap) Push(x interface{})

func (NodeHeap) Swap

func (h NodeHeap) Swap(i, j int)

type Pair

type Pair struct {
	// contains filtered or unexported fields
}

func NewPair

func NewPair(first, second interface{}) *Pair

func (*Pair) First

func (p *Pair) First() interface{}

func (*Pair) Second

func (p *Pair) Second() interface{}

type PairHeap

type PairHeap []*Pair

Pair

func (PairHeap) Len

func (ph PairHeap) Len() int

func (PairHeap) Less

func (ph PairHeap) Less(i, j int) bool

func (*PairHeap) Pop

func (ph *PairHeap) Pop() interface{}

func (*PairHeap) Push

func (ph *PairHeap) Push(val interface{})

func (PairHeap) Swap

func (ph PairHeap) Swap(i, j int)

type TreeNode

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

Definition for a binary tree node.

func BuildTree

func BuildTree(elements []int) *TreeNode

func InvertTree

func InvertTree(root *TreeNode) *TreeNode

func LowestCommonAncestor

func LowestCommonAncestor(root, p, q *TreeNode) *TreeNode

func LowestCommonAncestorII

func LowestCommonAncestorII(root, p, q *TreeNode) *TreeNode

func NewTreeNode

func NewTreeNode(val int) *TreeNode

Source Files

Jump to

Keyboard shortcuts

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