C++
Java
Python
Python3
C
C#
JavaScript
Ruby
Swift
Go
Scala
Kotlin
Rust
PHP
TypeScript
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 Solution {
public:
// Encodes a URL to a shortened URL.
string encode(string longUrl) {
}
// Decodes a shortened URL to its original URL.
string decode(string shortUrl) {
}
};
// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));
运行代码
提交
golang 解法, 执行用时: 0 ms, 内存消耗: 2.5 MB, 提交时间: 2021-06-08 14:35:07
type Codec struct {
mp map[string]string
count int
}
func Constructor() Codec {
return Codec{
mp: make(map[string]string),
count: 1,
}
}
// Encodes a URL to a shortened URL.
func (this *Codec) encode(longUrl string) string {
shortUrl := "http://tinyurl.com/" + strconv.Itoa(this.count)
this.mp[shortUrl] = longUrl
this.count++
return shortUrl
}
// Decodes a shortened URL to its original URL.
func (this *Codec) decode(shortUrl string) string {
return this.mp[shortUrl]
}
/**
* Your Codec object will be instantiated and called as such:
* obj := Constructor();
* url := obj.encode(longUrl);
* ans := obj.decode(url);
*/