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

Commitdd75347

Browse files
refactor 935
1 parent24c81ba commitdd75347

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
packagecom.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
publicclass_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
privatestaticfinalint[][]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
publicintknightDialer(intN) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp