Skip to content

Commit 24e24b2

Browse files
refactor 386
1 parent 4682f28 commit 24e24b2

File tree

1 file changed

+20
-30
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+20
-30
lines changed

src/main/java/com/fishercoder/solutions/_386.java

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,28 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
/**
7-
* 386. Lexicographical Numbers
8-
*
9-
* Given an integer n, return 1 - n in lexicographical order.
10-
*
11-
* For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].
12-
*
13-
* Please optimize your algorithm to use less time and space. The input size may be as large as
14-
* 5,000,000.
15-
*/
166
public class _386 {
17-
public static class Solution1 {
18-
//Radix sort doesn't apply here! Don't confuse yourself!
7+
public static class Solution1 {
8+
//Radix sort doesn't apply here! Don't confuse yourself!
199

20-
//rewrote their solution from Python to Java:https://discuss.leetcode.com/topic/54986/python-memory-limit-exceeded-for-problem-386/17
21-
public List<Integer> lexicalOrder(int n) {
22-
List<Integer> result = new ArrayList();
23-
int i = 1;
24-
while (true) {
25-
result.add(i);
26-
if (i * 10 <= n) {
27-
i *= 10;
28-
} else {
29-
while (i % 10 == 9 || i == n) {
30-
i /= 10;
31-
}
32-
if (i == 0) {
33-
return result;
34-
}
35-
i++;
10+
//rewrote their solution from Python to Java:https://discuss.leetcode.com/topic/54986/python-memory-limit-exceeded-for-problem-386/17
11+
public List<Integer> lexicalOrder(int n) {
12+
List<Integer> result = new ArrayList();
13+
int i = 1;
14+
while (true) {
15+
result.add(i);
16+
if (i * 10 <= n) {
17+
i *= 10;
18+
} else {
19+
while (i % 10 == 9 || i == n) {
20+
i /= 10;
21+
}
22+
if (i == 0) {
23+
return result;
24+
}
25+
i++;
26+
}
27+
}
3628
}
37-
}
3829
}
39-
}
4030
}

0 commit comments

Comments
 (0)