File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
main/java/com/fishercoder/solutions
test/java/com/fishercoder Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 29
29
public class _1165 {
30
30
public static class Solution1 {
31
31
public int calculateTime (String keyboard , String word ) {
32
- return -1 ;
32
+ int time = 0 ;
33
+ int fromIndex = 0 ;
34
+ int fingerMoves ;
35
+ for (char c : word .toCharArray ()) {
36
+ fingerMoves = Math .abs (fromIndex - keyboard .indexOf (c ));
37
+ fromIndex = keyboard .indexOf (c );
38
+ time += fingerMoves ;
39
+ }
40
+ return time ;
33
41
}
34
42
}
35
43
}
Original file line number Diff line number Diff line change
1
+ package com .fishercoder ;
2
+
3
+ import com .fishercoder .solutions ._1165 ;
4
+ import org .junit .BeforeClass ;
5
+ import org .junit .Test ;
6
+
7
+ import static org .junit .Assert .assertEquals ;
8
+
9
+ public class _1165Test {
10
+ private static _1165 .Solution1 solution1 ;
11
+ private static int [] nums ;
12
+
13
+ @ BeforeClass
14
+ public static void setup () {
15
+ solution1 = new _1165 .Solution1 ();
16
+ }
17
+
18
+ @ Test
19
+ public void test1 () {
20
+ assertEquals (4 , solution1 .calculateTime ("abcdefghijklmnopqrstuvwxyz" , "cba" ));
21
+ }
22
+
23
+ @ Test
24
+ public void test2 () {
25
+ assertEquals (73 , solution1 .calculateTime ("pqrstuvwxyzabcdefghijklmno" , "leetcode" ));
26
+ }
27
+
28
+ }
You can’t perform that action at this time.
0 commit comments