-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
36 lines (33 loc) · 936 Bytes
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution:
def decodeAtIndex(self, s: str, k: int) -> str:
size = 0
for c in s:
if c.isdigit():
size *= int(c)
else:
size += 1
for c in reversed(s):
k %= size
if k == 0 and c.isalpha():
return c
if c.isdigit():
size /= int(c)
else:
size -= 1
# class Solution:
# def decodeAtIndex(self, s: str, k: int) -> str:
# size, index = 0, 0
# while size < k:
# if s[index].isdigit():
# size *= int(s[index])
# else:
# size += 1
# index += 1
# for c in reversed(s[:index]):
# k %= size
# if c.isdigit():
# size /= int(c)
# elif k == 0:
# return c
# else:
# size -= 1