C++
Java
Python
Python3
C
C#
JavaScript
Ruby
Swift
Go
Scala
Kotlin
Rust
PHP
TypeScript
Racket
Erlang
Elixir
Dart
monokai
ambiance
chaos
chrome
cloud9_day
cloud9_night
cloud9_night_low_color
clouds
clouds_midnight
cobalt
crimson_editor
dawn
dracula
dreamweaver
eclipse
github
github_dark
gob
gruvbox
gruvbox_dark_hard
gruvbox_light_hard
idle_fingers
iplastic
katzenmilch
kr_theme
kuroir
merbivore
merbivore_soft
mono_industrial
nord_dark
one_dark
pastel_on_dark
solarized_dark
solarized_light
sqlserver
terminal
textmate
tomorrow
tomorrow_night
tomorrow_night_blue
tomorrow_night_bright
tomorrow_night_eighties
twilight
vibrant_ink
xcode
上次编辑到这里,代码来自缓存 点击恢复默认模板
class CQueue {
public:
CQueue() {
}
void appendTail(int value) {
}
int deleteHead() {
}
};
/**
* Your CQueue object will be instantiated and called as such:
* CQueue* obj = new CQueue();
* obj->appendTail(value);
* int param_2 = obj->deleteHead();
*/
运行代码
提交
golang 解法, 执行用时: 160 ms, 内存消耗: 8 MB, 提交时间: 2022-08-25 15:28:42
type CQueue struct {
inStack, outStack []int
}
func Constructor() CQueue {
return CQueue{}
}
func (this *CQueue) AppendTail(value int) {
this.inStack = append(this.inStack, value)
}
func (this *CQueue) DeleteHead() int {
if len(this.outStack) == 0 {
if len(this.inStack) == 0 {
return -1
}
this.in2out()
}
value := this.outStack[len(this.outStack)-1]
this.outStack = this.outStack[:len(this.outStack)-1]
return value
}
func (this *CQueue) in2out() {
for len(this.inStack) > 0 {
this.outStack = append(this.outStack, this.inStack[len(this.inStack)-1])
this.inStack = this.inStack[:len(this.inStack)-1]
}
}
/**
* Your CQueue object will be instantiated and called as such:
* obj := Constructor();
* obj.AppendTail(value);
* param_2 := obj.DeleteHead();
*/
python3 解法, 执行用时: 372 ms, 内存消耗: 19.2 MB, 提交时间: 2022-08-25 15:27:29
class CQueue:
def __init__(self):
self.q = []
def appendTail(self, value: int) -> None:
self.q.append(value)
def deleteHead(self) -> int:
if len(self.q) == 0: return -1
t = self.q[0]
self.q = self.q[1:]
return t
# Your CQueue object will be instantiated and called as such:
# obj = CQueue()
# obj.appendTail(value)
# param_2 = obj.deleteHead()
golang 解法, 执行用时: 292 ms, 内存消耗: 8.6 MB, 提交时间: 2021-06-10 20:53:28
type CQueue struct {
q []int
}
func Constructor() CQueue {
return CQueue{
q: []int{},
}
}
func (this *CQueue) AppendTail(value int) {
this.q = append(this.q, value)
}
func (this *CQueue) DeleteHead() int {
if len(this.q) == 0 {
return -1
}
t := this.q[0]
this.q = this.q[1:]
return t
}
/**
* Your CQueue object will be instantiated and called as such:
* obj := Constructor();
* obj.AppendTail(value);
* param_2 := obj.DeleteHead();
*/