Solution

package
v0.0.0-...-48c9e09 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: MIT Imports: 2 Imported by: 0

README

1. Add Sum

Problem

Description

Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.

We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i (1 <= i < n).

Example
Input: [4,2,3]
Output: True
Explanation: You could modify the first 4 to 1 to get a non-decreasing array.

Input: [4,2,1]
Output: False
Explanation: You can't get a non-decreasing array by modify at most one element.

Note: 如果array [i] <= array [i + 1]对于每个i(1 <= i <n)成立,我们定义一个数组是非递减的。

优先把 nums[i]降为nums[i+1],这样可以减少 nums[i+1] > nums[i+2] 的风险。

Solution

Approach1
Approach2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

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

define a new type Stack

func (*Stack) IsEmpty

func (s *Stack) IsEmpty() bool

Judge the stack is empty

func (*Stack) Len

func (s *Stack) Len() int

Return the stack len

func (*Stack) Pop

func (s *Stack) Pop() (interface{}, error)

Delete and Return the stack top val

func (*Stack) Push

func (s *Stack) Push(x int)

Push a val to stack top

func (*Stack) Top

func (s *Stack) Top() (interface{}, error)

Return the stack top val

Jump to

Keyboard shortcuts

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