algebra

package
v0.0.0-...-bced520 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutOfBound = errors.New("n must be less than 4000 and greater than 0")

ErrOutOfBound is a error that input number is not less than 4000 and greater than 0

Functions

func ClimbStairs

func ClimbStairs(x int) int

ClimbStairs returns there are how many distinct ways can you climb to the top. Each time you can either climb 1 or 2 steps. f(x) = f(x-1) + f(x-2)

func FindDisappearedNumbers

func FindDisappearedNumbers(nums []int) []int

FindDisappearedNumbers returns an array of all the integers in the range [1, n] that do not appear in nums.

func GetRow

func GetRow(n int) []int

GetRow returns the nth (0-indexed) row of the Pascal's triangle.

func IToR

func IToR(n int) (string, error)

IToR converts unsigned integer to a roman numeral. 1 <= num <= 3999

func IsHappyNum

func IsHappyNum(n int) bool

IsHappyNum returns true if a number n is happy. A happy number defined by follow process:

Starting with any positive integer, replace the number by the sum of the squares of its digits. Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy.

func IsUgly

func IsUgly(n int) bool

IsUgly returns true if n is a ugly number. Ugly number is a positive number whose prime factors only include 2, 3, and/or 5

func IsValidSerialization

func IsValidSerialization(preorder string) bool

IsValidSerialization returns true if it is a correct preorder traversal serialization of a binary tree.

func LongestOnes

func LongestOnes(A []int, K int) int

LongestOnes return the maximum number of consecutive 1's in the array if you can flip at most k 0's

origin:https://leetcode-cn.com/problems/max-consecutive-ones-iii

func MaximumScore

func MaximumScore(a int, b int, c int) int

MaximumScore returns step tha make a, b c be zero. Every step can minus two of a, b, c.

func MaximumUnits

func MaximumUnits(boxTypes [][]int, truckSize int) int

MaximumUnits returns the maximum number of boxes that can be put on the truck. The numberOfBoxes[i] is the number of boxes of type i. The numberOfUnitsPerBox[i] is the number of units in each box of the type i

func MyPow

func MyPow(x float64, n int) float64

MyPow implements pow(x, n), which calculates x raised to the power n (i.e., xn).

func PlusOne

func PlusOne(digits []int) []int

PlusOne increments the large integer by one and return the resulting array of digits.

func ReinitializePermutation

func ReinitializePermutation(n int) int

ReinitializePermutation returns the minimum non-zero number of operations you need to perform on perm to return the permutation to its initial value. Perm is a permutation perm of size n where perm[i] == i (0-indexed). In one operation, you will create a new array arr, and for each i: 1. If i % 2 == 0, then arr[i] = perm[i / 2] 2. If i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2]

func SearchInsert

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

SearchInsert return the index if the target is found. If not, return the index where it would be if it were inserted in order

func SmallestRepunitDivByK

func SmallestRepunitDivByK(k int) int

func SplitNum

func SplitNum(num int) int

func SqrtX

func SqrtX(x int) int

SqrtX returns the square root of x rounded down to the nearest integer.

func SumIndicesWithKSetBits

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

func ThreeSumClosest

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

ThreeSsumClosest returns the closest sum of three integers in nums to target

Types

type IntPair

type IntPair struct{ Left, Right int }

IntPair represents a pair of two int nums.

type NumArray

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

NumArray is used to calculate range sum of array.

func Constructor

func Constructor(nums []int) NumArray

Constructor returns a new NumArray.

func (*NumArray) SumRange

func (n *NumArray) SumRange(i int, j int) int

SumRange returns then sum of range (1, j).

Jump to

Keyboard shortcuts

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