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

Commitdb632c7

Browse files
Create 271-Encode-and-Decode-Strings.java
Added Readable code for Encoded and Decoded Strings java
1 parent6f46719 commitdb632c7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
publicclassSolution {
2+
3+
publicStringencode(List<String>strs) {
4+
StringBuilderencodedString =newStringBuilder();
5+
for(Stringstr:strs){
6+
intlength =str.length();
7+
encodedString.append(length+"#");
8+
encodedString.append(str);
9+
}
10+
returnencodedString.toString();
11+
}
12+
13+
publicList<String>decode(Stringstr) {
14+
List<String>decodedStrings =newArrayList();
15+
for(inti =0;i<str.length();i++){
16+
Stringlength ="";
17+
while(str.charAt(i) !='#'){
18+
length +=str.charAt(i);
19+
i++;
20+
}
21+
intwordLength =Integer.parseInt(length);
22+
i++;
23+
24+
Stringword ="";
25+
for(intj=i;j<wordLength+i;j++){
26+
word +=str.charAt(j);
27+
}
28+
decodedStrings.add(word);
29+
i=i+wordLength-1;
30+
}
31+
returndecodedStrings;
32+
}
33+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp