Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9b78cfc

Browse files
authored
Merge pull requestneetcode-gh#1622 from loczek/0535-encode-and-decode-tinyurl
Create: 0535-encode-and-decode-tinyurl.ts
2 parents8fd804c +d3cf047 commit9b78cfc

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
constencodeMap={};
2+
constdecodeMap={};
3+
letsize=0;
4+
5+
/**
6+
* Encodes a URL to a shortened URL.
7+
*/
8+
functionencode(longUrl:string):string{
9+
if(!encodeMap.hasOwnProperty(longUrl)){
10+
letshortUrl=size+1;
11+
size+=1;
12+
encodeMap[longUrl]=shortUrl;
13+
decodeMap[shortUrl]=longUrl;
14+
}
15+
16+
returnencodeMap[longUrl];
17+
}
18+
19+
/**
20+
* Decodes a shortened URL to its original URL.
21+
*/
22+
functiondecode(shortUrl:string):string{
23+
returndecodeMap[shortUrl];
24+
}
25+
26+
/**
27+
* Your functions will be called as such:
28+
* decode(encode(strs));
29+
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp