Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita608a97

Browse files
refactor 400
1 parentfdc411b commita608a97

File tree

2 files changed

+37
-39
lines changed

2 files changed

+37
-39
lines changed

‎src/main/java/com/fishercoder/solutions/_400.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,28 @@
2525
*/
2626
publicclass_400 {
2727

28-
/**credit: https://discuss.leetcode.com/topic/59314/java-solution:
29-
*
30-
* 1. find the length of the number where the nth digit is from
31-
* 2. find the actual number where the nth digit is from
32-
* 3. find the nth digit and return
33-
* */
34-
publicintfindNthDigit(intn) {
35-
intlen =1;
36-
longcount =9;
37-
intstart =1;
38-
39-
while (n >len *count) {
40-
n -=len *count;
41-
len +=1;
42-
count *=10;
43-
start *=10;
28+
publicstaticclassSolution1 {
29+
/**
30+
* credit: https://discuss.leetcode.com/topic/59314/java-solution:
31+
*
32+
* 1. find the length of the number where the nth digit is from 2. find the actual number where
33+
* the nth digit is from 3. find the nth digit and return
34+
*/
35+
publicintfindNthDigit(intn) {
36+
intlen =1;
37+
longcount =9;
38+
intstart =1;
39+
40+
while (n >len *count) {
41+
n -=len *count;
42+
len +=1;
43+
count *=10;
44+
start *=10;
45+
}
46+
47+
start += (n -1) /len;
48+
Strings =Integer.toString(start);
49+
returnCharacter.getNumericValue(s.charAt((n -1) %len));
4450
}
45-
46-
start += (n -1) /len;
47-
Strings =Integer.toString(start);
48-
returnCharacter.getNumericValue(s.charAt((n -1) %len));
4951
}
50-
5152
}

‎src/test/java/com/fishercoder/_400Test.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,22 @@
66

77
importstaticjunit.framework.Assert.assertEquals;
88

9-
/**
10-
* Created by fishercoder on 4/26/17.
11-
*/
129
publicclass_400Test {
13-
privatestatic_400test;
14-
privatestaticintexpected;
15-
privatestaticintactual;
16-
privatestaticintn;
10+
privatestatic_400.Solution1solution1;
11+
privatestaticintexpected;
12+
privatestaticintactual;
13+
privatestaticintn;
1714

18-
@BeforeClass
19-
publicstaticvoidsetup() {
20-
test=new_400();
21-
}
15+
@BeforeClass
16+
publicstaticvoidsetup() {
17+
solution1=new_400.Solution1();
18+
}
2219

23-
@Test
24-
publicvoidtest1() {
25-
n =11;
26-
expected =0;
27-
actual =test.findNthDigit(n);
28-
assertEquals(expected,actual);
29-
}
20+
@Test
21+
publicvoidtest1() {
22+
n =11;
23+
expected =0;
24+
actual =solution1.findNthDigit(n);
25+
assertEquals(expected,actual);
26+
}
3027
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp