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 DataStream {
public:
DataStream(int value, int k) {
}
bool consec(int num) {
}
};
/**
* Your DataStream object will be instantiated and called as such:
* DataStream* obj = new DataStream(value, k);
* bool param_1 = obj->consec(num);
*/
运行代码
提交
golang 解法, 执行用时: 292 ms, 内存消耗: 37.2 MB, 提交时间: 2023-01-09 10:46:59
type DataStream struct{ value, k, cnt int }
func Constructor(value, k int) DataStream {
return DataStream{value, k, 0}
}
func (d *DataStream) Consec(num int) bool {
if num == d.value {
d.cnt++
} else {
d.cnt = 0
}
return d.cnt >= d.k
}
/**
* Your DataStream object will be instantiated and called as such:
* obj := Constructor(value, k);
* param_1 := obj.Consec(num);
*/
python3 解法, 执行用时: 424 ms, 内存消耗: 45 MB, 提交时间: 2023-01-09 10:46:43
class DataStream:
def __init__(self, value: int, k: int):
self.value = value
self.k = k
self.cnt = 0
def consec(self, num: int) -> bool:
self.cnt = 0 if num != self.value else self.cnt + 1
return self.cnt >= self.k
# Your DataStream object will be instantiated and called as such:
# obj = DataStream(value, k)
# param_1 = obj.consec(num)