算法
Forest Young
这个作者很懒,什么都没留下…
展开
-
队列的栈实现
LeetCode 232. 用栈实现队列请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、peek、empty):实现 MyQueue 类:void push(int x) 将元素 x 推到队列的末尾int pop() 从队列的开头移除并返回元素int peek() 返回队列开头的元素boolean empty() 如果队列为空,返回 true ;否则,返回 false来源:力扣(LeetCode)链接:https://leetcode-cn.com/p原创 2021-03-08 20:34:02 · 179 阅读 · 0 评论 -
使用栈实现DFS
/** * 以二叉树为例使用栈实现DFS算法 * * @author dongyang * @date 2021年03月07日 14:50 */public class StackDFS { private List<Integer> list = new ArrayList<>(); public void dfs(BinaryTreeNode node) { if (null == node) { return;原创 2021-03-07 15:37:15 · 2788 阅读 · 2 评论 -
使用递归实现DFS
/** * 以二叉树为例使用递归实现DFS算法 * * @author Forest * @date 2021年03月07日 14:35 */public class RecursionDFS { private List<Integer> list = new ArrayList<>(); public void dfs(BinaryTreeNode node) { if (null == node) { ret原创 2021-03-07 15:32:03 · 401 阅读 · 0 评论