goden0301

package
v0.0.0-...-b071cee Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 0 Imported by: 0

README

面试题 03.01.三合一

1. 题目描述

三合一。描述如何只用一个数组来实现三个栈。

你应该实现 push(stackNum, value)pop(stackNum)isEmpty(stackNum)peek(stackNum) 方法。 stackNum 表示栈下标, value 表示压入的值。

构造函数会传入一个 stackSize 参数,代表每个栈的大小。

示例1:


 输入:
["TripleInOne", "push", "push", "pop", "pop", "pop", "isEmpty"]
[[1], [0, 1], [0, 2], [0], [0], [0], [0]]
 输出:
[null, null, null, 1, -1, -1, true]
说明:当栈为空时`pop, peek`返回-1,当栈满时`push`不压入元素。

示例2:


 输入:
["TripleInOne", "push", "push", "push", "pop", "pop", "pop", "peek"]
[[2], [0, 1], [0, 2], [0, 3], [0], [0], [0], [0]]
 输出:
[null, null, null, null, 2, 1, -1, -1]

提示:

  • 0 <= stackNum <= 2

标签 设计 数组

2. 解题

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TripleInOne

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

func Constructor

func Constructor(stackSize int) TripleInOne

func (*TripleInOne) IsEmpty

func (this *TripleInOne) IsEmpty(stackNum int) bool

func (*TripleInOne) Peek

func (this *TripleInOne) Peek(stackNum int) int

func (*TripleInOne) Pop

func (this *TripleInOne) Pop(stackNum int) int

func (*TripleInOne) Push

func (this *TripleInOne) Push(stackNum int, value int)

Jump to

Keyboard shortcuts

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