Skip to content

Commit 26229d2

Browse files
authored
30 september 2023
1 parent 7980c4e commit 26229d2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

880. Decoded String at Index

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Runtime 0 ms
2+
Beats 100%
3+
4+
5+
Memory 40.2 MB
6+
Beats 55.51%
7+
8+
9+
class Solution {
10+
public String decodeAtIndex(String s, int k) {
11+
long size=0;
12+
13+
for(char c:s.toCharArray()){
14+
if(Character.isDigit(c))
15+
size=size*(c-'0');
16+
else
17+
size++;
18+
}
19+
20+
for(int i=s.length()-1;i>=0;i--){
21+
char c=s.charAt(i);
22+
k%=size;
23+
if((k==0 || k==size) && Character.isLetter(c))
24+
return Character.toString(c);
25+
if(Character.isDigit(c))
26+
size=size/(c-'0');
27+
else
28+
size--;
29+
}
30+
31+
return null;
32+
}
33+
}

0 commit comments

Comments
 (0)