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 9fae430 commit c37d27dCopy full SHA for c37d27d
400. Nth Digit.java
@@ -0,0 +1,32 @@
1
+// Brute (Memory Limit)
2
+public class Solution {
3
+ public int findNthDigit(int n) {
4
+ StringBuilder sb = new StringBuilder();
5
+
6
+ for (int i = 1; ; i++) {
7
+ sb.append(i);
8
9
+ if (sb.length() >= n) {
10
+ return sb.charAt(n-1) - '0';
11
+ }
12
13
14
+}
15
16
+// Space improvement (Time Limit)
17
18
19
20
21
22
23
24
+ if (n > sb.length()) {
25
+ n -= sb.length();
26
+ sb.delete(0, sb.length());
27
+ } else {
28
29
30
31
32
0 commit comments