Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day284:如何用栈实现一个队列 #1105

Open
Genzhen opened this issue Apr 20, 2021 · 0 comments
Open

Day284:如何用栈实现一个队列 #1105

Genzhen opened this issue Apr 20, 2021 · 0 comments
Labels
算法 teach_tag

Comments

@Genzhen
Copy link
Collaborator

Genzhen commented Apr 20, 2021

push(x) // 将一个元素放入队列的尾部。
pop()  // 队列首部移除元素。
peek()  // 返回队列首部的元素。
empty() // 返回队列是否为空。

// 示例
MyQueue queue = new MyQueue();
queue.push(1);
queue.push(2);
queue.peek(); // 返回 1
queue.pop(); // 返回 1
queue.empty(); // 返回 false

// 说明
// 只能使用标准的栈操作 -- 也就是只有 push to top, peek/pop from top, size, 和 is empty 操作是合法的。
// 假设所有操作都是有效的 (例如,一个空的队列不会调用 pop 或者 peek 操作)。

每日一题会在下午四点在交流群集中讨论,五点小程序中更新答案
欢迎大家在下方发表自己的优质见解

二维码加载失败可点击 小程序二维码

扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。

@Genzhen Genzhen added the 算法 teach_tag label Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
算法 teach_tag
Projects
None yet
Development

No branches or pull requests

1 participant