We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f65450e commit c0bc4abCopy full SHA for c0bc4ab
Medium/Decoded String at Index.java
@@ -0,0 +1,27 @@
1
+class Solution {
2
+ public String decodeAtIndex(String s, int k) {
3
+ long size = 0;
4
+ int n = s.length();
5
+ for (int i = 0; i < n; i++) {
6
+ char c = s.charAt(i);
7
+ if (Character.isDigit(c)) {
8
+ size *= (c - '0');
9
+ } else {
10
+ size++;
11
+ }
12
13
+ for (int i = n - 1; i >= 0; i--) {
14
15
+ k %= size;
16
+ if (k == 0 && Character.isLetter(c)) {
17
+ return Character.toString(c);
18
19
20
+ size /= (c - '0');
21
22
+ size--;
23
24
25
+ return "";
26
27
+}
0 commit comments