Skip to content

Commit dd75347

Browse files
refactor 935
1 parent 24c81ba commit dd75347

File tree

1 file changed

+3
-33
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-33
lines changed

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

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 935. Knight Dialer
5-
*
6-
* A chess knight can move as indicated in the chess diagram below:
7-
*
8-
* https://assets.leetcode.com/uploads/2018/10/12/knight.png
9-
*
10-
* |---|---|---|
11-
* | 1 | 2 | 3 |
12-
* |---|---|---|
13-
* | 4 | 5 | 6 |
14-
* |---|---|---|
15-
* | 7 | 8 | 9 |
16-
* |---|---|---|
17-
* | x | 0 | x |
18-
* |---|---|---|
19-
*
20-
* This time, we place our chess knight on any numbered key of a phone pad (indicated above), and the knight makes N-1 hops.
21-
* Each hop must be from one key to another numbered key.
22-
*
23-
* Each time it lands on a key (including the initial placement of the knight), it presses the number of that key, pressing N digits total.
24-
*
25-
* How many distinct numbers can you dial in this manner?
26-
*
27-
* Since the answer may be large, output the answer modulo 10^9 + 7.
28-
*
29-
* Note:
30-
* * 1 <= N <= 5000
31-
*/
32-
333
public class _935 {
344
/*
355
* The intuition is to calculate the number of ways
@@ -50,9 +20,9 @@ public static class Solution1 {
5020

5121
// whereFromHere[i] is an array of keys that can be reached from the ith digit
5222
private static final int[][] whereFromHere = {
53-
{4, 6}, {6, 8}, {7, 9}, {4, 8}, // 0, 1, 2, 3
54-
{3, 9, 0}, {}, {1, 7, 0}, // 4, 5, 6
55-
{2, 6}, {1, 3}, {2, 4} // 7, 8, 9
23+
{4, 6}, {6, 8}, {7, 9}, {4, 8}, // 0, 1, 2, 3
24+
{3, 9, 0}, {}, {1, 7, 0}, // 4, 5, 6
25+
{2, 6}, {1, 3}, {2, 4} // 7, 8, 9
5626
};
5727

5828
public int knightDialer(int N) {

0 commit comments

Comments
 (0)