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

Commit4d2d83d

Browse files
committed
Merge pull requestneetcode-gh#133 from IbuAR/271-Encode-and-Decode-Strings.js
Add 271-Encode-and-Decode-Strings.js
2 parents1217081 +55fa53e commit4d2d83d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
*@param {string[]} strs
3+
*@return {string}
4+
*/
5+
varencode=function(strs){
6+
letres="";
7+
for(constsofstrs)res+=String(s.length)+"#"+s;
8+
returnres;
9+
}
10+
11+
/**
12+
*@param {string} str
13+
*@return {string[]}
14+
*/
15+
vardecode=function(str){
16+
constres=[];
17+
leti=0;
18+
19+
while(i<str.length){
20+
letj=i;
21+
while(str[j]!="#")j+=1;
22+
23+
length=Number(str.slice(i,j));
24+
res.push(str.slice(j+1,j+1+length));
25+
i=j+1+length;
26+
}
27+
28+
returnres;
29+
}
30+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp