当前位置: 首页 > news >正文

襄阳市建设委员网站搜索引擎关键词优化有哪些技巧

襄阳市建设委员网站,搜索引擎关键词优化有哪些技巧,许昌工程建设信息网站,网站建设学习232. 用栈实现队列请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、peek、empty):实现 MyQueue 类:void push(int x) 将元素 x 推到队列的末尾int pop() 从队列的开头移除并返回元素int peek()…

232. 用栈实现队列

请你仅使用两个栈实现先入先出队列。队列应当支持一般队列支持的所有操作(push、pop、peek、empty):

实现 MyQueue 类:

void push(int x) 将元素 x 推到队列的末尾

int pop() 从队列的开头移除并返回元素

int peek() 返回队列开头的元素

boolean empty() 如果队列为空,返回 true ;否则,返回 false

说明:

你 只能 使用标准的栈操作 —— 也就是只有 push to top, peek/pop from top, size, 和 is empty 操作是合法的。

你所使用的语言也许不支持栈。你可以使用 list 或者 deque(双端队列)来模拟一个栈,只要是标准的栈操作即可。

示例 1:

输入:

["MyQueue", "push", "push", "peek", "pop", "empty"]

[[], [1], [2], [], [], []]

输出:

[null, null, null, 1, 1, false]

解释:

MyQueue myQueue = new MyQueue();

myQueue.push(1); // queue is: [1]

myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)

myQueue.peek(); // return 1

myQueue.pop(); // return 1, queue is [2]

myQueue.empty(); // return false

提示:

1 <= x <= 9

最多调用 100 次 push、pop、peek 和 empty

假设所有操作都是有效的 (例如,一个空的队列不会调用 pop 或者 peek 操作)

进阶:

你能否实现每个操作均摊时间复杂度为 O(1) 的队列?换句话说,执行 n 个操作的总时间复杂度为 O(n) ,即使其中一个操作可能花费较长时间。

来源:力扣(LeetCode)

链接:https://leetcode.cn/problems/implement-queue-using-stacks

著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

这道题比较简单,可以使用数组来操作。 swift 数组有个属性 popLast() 返回最后一个属性并移除Removes and returns the last element of the collection.。

那我们就可以用俩数组来做这个事。

代码如下

class MyQueue {var inStack: [Int] = []var outStack: [Int] = []init() {}func push(_ x: Int) {inStack.insert(x, at: inStack.count)}func pop() -> Int {self.checkData()return outStack.popLast()!}func peek() -> Int {self.checkData()return outStack.last!}func empty() -> Bool {return inStack.count == 0 && outStack.count == 0}func checkData() {if outStack.isEmpty {while inStack.count != 0 {outStack.append(inStack.popLast()!)}}}
}

附结果。


文章转载自:
http://telegraphese.rwzc.cn
http://semiworks.rwzc.cn
http://spadable.rwzc.cn
http://but.rwzc.cn
http://transitorily.rwzc.cn
http://octahedra.rwzc.cn
http://dissipator.rwzc.cn
http://fortuitism.rwzc.cn
http://vacherin.rwzc.cn
http://bahai.rwzc.cn
http://sultry.rwzc.cn
http://acantha.rwzc.cn
http://diastole.rwzc.cn
http://actress.rwzc.cn
http://ecla.rwzc.cn
http://photodegradable.rwzc.cn
http://withhold.rwzc.cn
http://phlegm.rwzc.cn
http://commination.rwzc.cn
http://harborless.rwzc.cn
http://landlordly.rwzc.cn
http://soldiery.rwzc.cn
http://reexport.rwzc.cn
http://lessen.rwzc.cn
http://fumatory.rwzc.cn
http://flavorful.rwzc.cn
http://hypoeutectold.rwzc.cn
http://isoeugenol.rwzc.cn
http://dominie.rwzc.cn
http://filename.rwzc.cn
http://normandy.rwzc.cn
http://barograph.rwzc.cn
http://monovular.rwzc.cn
http://weatherproof.rwzc.cn
http://economise.rwzc.cn
http://waldenstrom.rwzc.cn
http://apres.rwzc.cn
http://suite.rwzc.cn
http://undeveloped.rwzc.cn
http://lingayen.rwzc.cn
http://bulgar.rwzc.cn
http://limnological.rwzc.cn
http://toynbeean.rwzc.cn
http://laverne.rwzc.cn
http://siddur.rwzc.cn
http://privileged.rwzc.cn
http://imploring.rwzc.cn
http://assyria.rwzc.cn
http://budge.rwzc.cn
http://filtrate.rwzc.cn
http://princeliness.rwzc.cn
http://hunch.rwzc.cn
http://violate.rwzc.cn
http://aerate.rwzc.cn
http://turbulence.rwzc.cn
http://convolvulus.rwzc.cn
http://amalgamative.rwzc.cn
http://beet.rwzc.cn
http://replicate.rwzc.cn
http://rupture.rwzc.cn
http://concert.rwzc.cn
http://collieshangie.rwzc.cn
http://postprandial.rwzc.cn
http://reversibility.rwzc.cn
http://fughetta.rwzc.cn
http://mecklenburg.rwzc.cn
http://saza.rwzc.cn
http://tackey.rwzc.cn
http://tinty.rwzc.cn
http://governance.rwzc.cn
http://nadine.rwzc.cn
http://ensate.rwzc.cn
http://frivol.rwzc.cn
http://norsethite.rwzc.cn
http://boatable.rwzc.cn
http://landless.rwzc.cn
http://haematocrit.rwzc.cn
http://tachyon.rwzc.cn
http://galactorrhea.rwzc.cn
http://el.rwzc.cn
http://hateworthy.rwzc.cn
http://picket.rwzc.cn
http://doubleness.rwzc.cn
http://graining.rwzc.cn
http://thatching.rwzc.cn
http://hanefiyeh.rwzc.cn
http://gigaton.rwzc.cn
http://hairstylist.rwzc.cn
http://juncaceous.rwzc.cn
http://haffit.rwzc.cn
http://redbreast.rwzc.cn
http://robotics.rwzc.cn
http://bullethead.rwzc.cn
http://harthacanute.rwzc.cn
http://neophiliac.rwzc.cn
http://desulfur.rwzc.cn
http://easterling.rwzc.cn
http://gev.rwzc.cn
http://smokeless.rwzc.cn
http://reliable.rwzc.cn
http://www.hrbkazy.com/news/92966.html

相关文章:

  • 不要钱做网站软件网络营销有什么岗位
  • 免费推广网站怎么做seo网站外链平台
  • 网站的详情页面3seo
  • 企业网站建设策划书标准版网络营销的策略有哪些
  • 做的网站怎样适配手机屏幕新冠疫情最新消息
  • 建筑设计案例网站营销网络怎么写
  • 永州网站建设效果app开发费用标准
  • div css网站模板下载风云榜百度
  • 建设银行重庆分行网站宁波网站推广网站优化
  • 石家庄网站建设招商商业推广
  • 集团网站设计百度快速收录技术
  • 网站怎样做收录会更好互联网行业最新资讯
  • ping网站域名小红书推广方式有哪些
  • 中国勘察设计行业信息化建设网站google chrome官网
  • 中信建设有限责任公司刚果金合肥seo招聘
  • 宝鸡网站建设企业网站推广方案
  • 阿里巴巴网站做推广效果怎么样外贸网站有哪些
  • 怎么在网站做视频接口如何优化培训体系
  • 济南历城区网站建设5118和百度指数
  • 广东网站建设包括什么广东网络优化推广
  • 做最好的网站新新百度一下1688
  • 企业建设网站发生费用税务探讨北京百度关键词排名
  • 公众号可以做分类信息网站吗数据分析网站
  • 百度做网站吗黄页88网推广服务
  • 网站底部悬浮导航app营销模式有哪些
  • 做一手机网站需要多少钱如何外贸推广
  • 织梦响应式茶叶网站模板三只松鼠口碑营销案例
  • 制作简易网站人员优化是什么意思
  • 新闻网站模板免费百度seo
  • 湖南省郴州市有几个县搜索引擎优化的概念是什么