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 22fa926 commit 9950973Copy full SHA for 9950973
java/0880-decoded-string-at-index.java
@@ -0,0 +1,34 @@
1
+/*
2
+-----------------------
3
+ Time Complexity : O(n)
4
+ Space Complexity = O(1)
5
6
+*/
7
+
8
+class Solution {
9
+ public String decodeAtIndex(String s, int k) {
10
+ long wordLength = 0;
11
+ for (char c : s.toCharArray()) {
12
+ if (Character.isLetter(c)) {
13
+ wordLength += 1;
14
+ } else {
15
+ wordLength *= Character.getNumericValue(c);
16
+ }
17
18
19
+ for (int i = s.length() - 1; i >= 0; i--) {
20
+ char c = s.charAt(i);
21
+ k %= wordLength;
22
23
+ if (k == 0) {
24
+ return String.valueOf(c);
25
26
+ wordLength -= 1;
27
28
29
+ wordLength /= Character.getNumericValue(c);
30
31
32
+ return "";
33
34
+}
0 commit comments