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 LUPrefix {
public:
LUPrefix(int n) {
}
void upload(int video) {
}
int longest() {
}
};
/**
* Your LUPrefix object will be instantiated and called as such:
* LUPrefix* obj = new LUPrefix(n);
* obj->upload(video);
* int param_2 = obj->longest();
*/
运行代码
提交
golang 解法, 执行用时: 368 ms, 内存消耗: 61.8 MB, 提交时间: 2022-11-21 11:44:18
type LUPrefix struct {
x int
has map[int]bool
}
func Constructor(int) LUPrefix {
return LUPrefix{1, map[int]bool{}}
}
func (p LUPrefix) Upload(video int) {
p.has[video] = true
}
// 时间复杂度:均摊 O(1)
func (p *LUPrefix) Longest() int {
for p.has[p.x] {
p.x++
}
return p.x - 1
}
/**
* Your LUPrefix object will be instantiated and called as such:
* obj := Constructor(n);
* obj.Upload(video);
* param_2 := obj.Longest();
*/
python3 解法, 执行用时: 456 ms, 内存消耗: 73.4 MB, 提交时间: 2022-11-21 11:43:53
class LUPrefix:
def __init__(self, n: int):
self.x = 1
self.s = set()
def upload(self, video: int) -> None:
self.s.add(video)
# 时间复杂度:均摊 O(1)
def longest(self) -> int:
while self.x in self.s:
self.x += 1
return self.x - 1
# Your LUPrefix object will be instantiated and called as such:
# obj = LUPrefix(n)
# obj.upload(video)
# param_2 = obj.longest()