Skip to content

Commit 24e7b64

Browse files
Time: 32 ms (81.09%) | Memory: 16.3 MB (94.53%) - LeetSync
1 parent 7a65587 commit 24e7b64

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def findKthNumber(self, n: int, k: int) -> int:
3+
def getSteps(x):
4+
res = 0
5+
diff = 1
6+
while x <= n:
7+
res += min(diff, n-x+1)
8+
x *= 10
9+
diff *= 10
10+
return res
11+
12+
ans = 1
13+
while k > 1:
14+
steps = getSteps(ans)
15+
if k > steps:
16+
k -= steps
17+
ans += 1
18+
else:
19+
k -= 1
20+
ans *= 10
21+
return ans

0 commit comments

Comments
 (0)