Skip to content

Commit

Permalink
auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
CyC2018 committed Nov 3, 2020
1 parent 10ecb91 commit c29021b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions docs/notes/30. 包含 min 函数的栈.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# 30. 包含 min 函数的栈

[NowCoder](https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49?tpId=13&tqId=11173&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
## 题目链接

[牛客网](https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49?tpId=13&tqId=11173&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)

## 题目描述

定义栈的数据结构请在该类型中实现一个能够得到栈最小元素的 min 函数
实现一个包含 min() 函数的栈该方法返回当前栈中最小的值

## 解题思路

使用一个额外的 minStack栈顶元素为当前栈中最小的值在对栈进行 push 入栈和 pop 出栈操作时同样需要对 minStack 进行入栈出栈操作从而使 minStack 栈顶元素一直为当前栈中最小的值在进行 push 操作时需要比较入栈元素和当前栈中最小值将值较小的元素 push minStack

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/image-20201104013936126.png" alt="image-20201104013936126" style="zoom:50%;" /> </div><br>

```java
private Stack<Integer> dataStack = new Stack<>();
private Stack<Integer> minStack = new Stack<>();
Expand Down
10 changes: 8 additions & 2 deletions notes/30. 包含 min 函数的栈.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# 30. 包含 min 函数的栈

[NowCoder](https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49?tpId=13&tqId=11173&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)
## 题目链接

[牛客网](https://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49?tpId=13&tqId=11173&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github)

## 题目描述

定义栈的数据结构请在该类型中实现一个能够得到栈最小元素的 min 函数
实现一个包含 min() 函数的栈该方法返回当前栈中最小的值

## 解题思路

使用一个额外的 minStack栈顶元素为当前栈中最小的值在对栈进行 push 入栈和 pop 出栈操作时同样需要对 minStack 进行入栈出栈操作从而使 minStack 栈顶元素一直为当前栈中最小的值在进行 push 操作时需要比较入栈元素和当前栈中最小值将值较小的元素 push minStack

<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/image-20201104013936126.png" alt="image-20201104013936126" style="zoom:50%;" /> </div><br>

```java
private Stack<Integer> dataStack = new Stack<>();
private Stack<Integer> minStack = new Stack<>();
Expand Down
Binary file added notes/pics/image-20201104013936126.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c29021b

Please sign in to comment.