ICode9

精准搜索请尝试: 精确搜索
  • 33 | JAVA集合Stack(一种接口,不推荐使用)2022-09-02 09:01:49

    Stack 栈(Stack)是一种后进先出(LIFO:Last In First Out)的数据结构。 Stack只有入栈和出栈的操作: 把元素压栈:push(E); 把栈顶的元素“弹出”:pop(); 取栈顶元素但不弹出:peek()。 在Java中,我们用Deque可以实现Stack的功能: 把元素压栈:push(E)/addFirst(E); 把栈顶的元素“弹出”:pop()/rem

  • leetcode42-接雨水2022-08-18 13:31:56

    接雨水 dp 维护两个dp数组,分别记录左侧和右侧的最大值。当前位置的雨水就是左右两侧最大值的较小值减去当前位置的高度,将所有雨水累加即可得到结果。 class Solution { public int trap(int[] height) { int n = height.length, left[] = new int[n], right[] = new

  • leetcode 232. Implement Queue using Stacks 用栈实现队列(简单)2022-08-07 20:30:23

    一、题目大意 标签: 栈和队列 https://leetcode.cn/problems/implement-queue-using-stacks 请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、peek、empty): 实现 MyQueue 类: void push(int x) 将元素 x 推到队列的末尾 int pop() 从队列的开头移

  • How to: View and edit code by using Peek Definition (Alt+F12)2022-07-03 15:01:07

    How to: View and edit code by using Peek Definition (Alt+F12) You can use the Peek Definition command to view and edit code without switching away from the code that you're writing. Peek Definition and Go To Definition show the same information, but

  • 22.用栈实现队列2022-06-20 16:03:56

    232. 用栈实现队列 请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、peek、empty): 实现 MyQueue 类: void push(int x) 将元素 x 推到队列的末尾 int pop() 从队列的开头移除并返回元素 int peek() 返回队列开头的元素 boolean empty() 如果队列

  • LeetCode 0155 Min Stack2022-05-25 20:02:06

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 用两个栈来实现,s1是数据输入栈,s2是s1中对应位置元素的最小值。 2、代码实现 package Q0199.Q0155MinStack; import java.util.Stack; public class MinStack { private Stack<Integer> s1 = new Stack<>(); private

  • 每日温度2022-05-20 12:00:50

    给定一个整数数组 temperatures ,表示每天的温度,返回一个数组 res ,其中 res[i]是指在第 i 天之后,才会有更高的温度。如果气温在这之后都不会升高,请在该位置用 0 来代替。 暴力解法:两层for循环即可 class Solution { public int[] dailyTemperatures(int[] temperatures) {

  • 最大栈2022-05-07 23:01:15

    题目: 思路: ​ 使用一个主栈(stack)+辅助栈(assistStack),assistStack 的栈顶永远是最大值。 1、push: 1.1 对于 stack 来说,直接push即可:stack.push(x); 1.2 对于 assistStack 来说,要进行判断,它 push 待插入的 x 和它栈顶两者最大的那个; 2、pop:两个栈都 pop,返回 stak 的 pop 值; 3、

  • 函数式编程 jdk10中stream流里面peek方法2022-04-04 11:31:47

    最近在我的课程里面SpringBoot2.0不容错过的新特性 WebFlux响应式编程里面,有学员提出了以下问题,在jdk10里面代码没有执行(课程中stream流是用jdk8演示的)   代码: public class LambdaDemo { public static void main(String[] args) { IntStream.range(1,10).peek(Lamb

  • 算法基础提升——滑动窗口、单调栈和单调栈的应用2022-03-29 15:35:38

    package com.zuoshen.jichutisheng.class04; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.Stack; /** * @author ShiZhe * @create 2022-03-28 19:45 */ public class code01 { /** * 滑动窗口 *

  • 21-js数据结构——栈2022-03-25 15:00:38

    栈是一种高效的数据结构,数据只能在栈顶添加或删除,所以这样操作很快,也很容易实现。栈的使用遍布程序语言实现的方方面面,从表达式求值到处理函数调用。接下来,用JavaScript实现一个栈的数据结构。 定义栈的操作 栈作为一种特殊的列表,只能从一端来进行访问,就像一摞盘子,放只能放在上面,

  • 【栈与队列】232. 用栈实现队列2022-03-20 17:30:05

    题目: 请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、peek、empty): 实现 MyQueue 类: void push(int x) 将元素 x 推到队列的末尾 int pop() 从队列的开头移除并返回元素 int peek() 返回队列开头的元素 boolean empty() 如果队列为空,返回 true

  • 编译原理答案@2.62022-02-22 20:02:30

    Exercises for Section 2.6 2.6.1 Extend the lexical analyzer in Section 2.6.5 to remove comments, defined as follows: A comment begins with // and includes all characters until the end of that line. A comment begins with /* and includes all characters thr

  • 【Leetcode刷题笔记】 单调栈2022-02-20 19:32:24

    最近刷题的时候碰到很多单调栈的问题,特此记录下来,省的以后全忘了。 单调栈问题都有一个特点,就是大多数的栈存的并不直接是元素,而是下标,通过下标去做判断。 单调栈,顾名思义就是栈内存储的元素是非递增或者是非递减的,方便进行遍历 Q1 LeetCode739 每日温度 请根据每日 气温 列

  • 力扣42、接雨水(单调栈思想)2022-02-09 16:00:23

    链接:42. 接雨水 - 力扣(LeetCode) (leetcode-cn.com)  本题将采用单调栈的思想来解 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 思路: 利用一个栈,这个栈是从低到高依次递减的单调栈 先将第一个柱子放入栈,以方便后续操作

  • 剑指offer_30_包含min函数的栈_单调栈 / 数据结构2022-02-02 16:01:30

    很经典的一道题,如果没做过,我感觉还是挺难想的。题解是用了单调栈作为辅助栈。 其实仔细看这道题,要求push和pop都是O1,所以还是必须得用栈,无非多要求了个min,我们将每层的min存进去就好了其实。 class MinStack { Deque<int[]> deque = new ArrayDeque<>(); /** initia

  • 【2022初春】【LeetCode】232. 用栈实现队列2022-02-01 22:30:16

    一遍过了,中间差一个判断 class MyQueue { Stack<Integer> a; Stack<Integer> b; public MyQueue() { a = new Stack<Integer>(); b = new Stack<Integer>(); } public void push(int x) { a.push(x);

  • 力扣 155. 最小栈2022-01-28 00:03:18

    题目:   分析:         原本傻傻的自己写了个栈,写完一看题解可以用stack,在下面有个评论说面试时问到怎么不用辅助栈,于是结合思考了一下,自己写了一下代码。         他就是在原有栈存一个int的情况下,扩城int[ ]存放两个元素,一个是val,一个是动态规划下来现有栈的最小值。

  • JAVA Leetcode232. 用栈实现队列2022-01-24 16:58:00

    232. 用栈实现队列 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/implement-queue-using-stacks 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 题目 请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、

  • [LeetCode] 232. Implement Queue using Stacks2022-01-17 07:32:00

    mplement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: void push(int x) Pushes element x to the back of the que

  • 线性栈实现中缀表达式计算器2022-01-10 09:58:55

    线性栈实现中缀表达式计算器 方法代码: 以(10+20/2*3)/2+8为例(计算结果为28): private static int evaluateExpression(String expression){ //创建两个栈,一个存放符号,一个存放数字 ArrayStack<Character> operatorStack = new ArrayStack<>(); ArrayS

  • 数据结构实现相关2022-01-09 23:33:39

    232. Implement Queue using Stacks Easy Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: void push

  • 一刷28-栈与队列-232用栈实现队列(e)2022-01-09 12:00:16

    题目: 请你仅使用两个栈实现 先入先出队列。 队列应当支持一般队列支持的所有操作(push、pop、peek、empty): 实现 MyQueue 类: void push(int x) 将元素 x 推到队列的末尾 int pop() 从队列的开头移除并返回元素 int peek() 返回队列开头的元素 boolean empty() 如果队列为空,返

  • 【力扣学习计划】包含min函数的栈2022-01-05 16:03:12

    最开始图省事,搞了一个list,在min函数被调用时将栈内现有数据全部排序后返回最小值 由于性能太差,考虑一个新的思路 设计思路:由两个栈组成,A栈作为元素栈,B栈作为最小元素栈push元素进栈时,和B栈栈顶元素比较,如果更小或相等则压入,否则不处理pop元素出栈时,和B栈栈顶元素比较,如果相等则B栈

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有