matrix

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: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateMatrix

func GenerateMatrix(n int) [][]int

GenerateMatrix generates an n x n matrix filled with elements from 1 to n2 in spiral order.

func KWeakRows

func KWeakRows(mat [][]int, k int) []int

KWeakRows the indices of the k weakest rows in the matrix ordered from weakest to strongest, mat is an m x n binary matrix. A row i is weaker than a row j if one of the following is true: - The number of 1 in row i is less than the number of 1 in row j. - Both rows have the same number of 1 and i < j.

func Reshape

func Reshape(nums [][]int, r int, c int) [][]int

Reshape reshapes the matrix from m * n to r * c

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

Search searches for a value in an m x n matrix.

func SetZeroes

func SetZeroes(matrix [][]int)

func SpiralOrder

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

SpiralOrder returns all elements of the matrix in spiral order.

Types

type NumMatrix

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

NumMatrix is used to calculate matrix region sum.

func NewNumMatrix

func NewNumMatrix(matrix [][]int) NumMatrix

NewNumMatrix builds NumMatrix from [][]int slice.

func (*NumMatrix) SumRegion

func (n *NumMatrix) SumRegion(row1 int, col1 int, row2 int, col2 int) int

SumRegion calculates the sum of matrix region.

Jump to

Keyboard shortcuts

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