Skip to content

Commit 7e15f7c

Browse files
refactor 351
1 parent 850a318 commit 7e15f7c

File tree

1 file changed

+2
-34
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-34
lines changed

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

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

3-
/**
4-
* 351. Android Unlock Patterns
5-
*
6-
* Given an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total number of unlock patterns of the Android lock screen, which consist of minimum of m keys and maximum n keys.
7-
8-
Rules for a valid pattern:
9-
Each pattern must connect at least m keys and at most n keys.
10-
All the keys must be distinct.
11-
If the line connecting two consecutive keys in the pattern passes through any other keys, the other keys must have previously selected in the pattern. No jumps through non selected key is allowed.
12-
The order of keys used matters.
13-
14-
Explanation:
15-
| 1 | 2 | 3 |
16-
| 4 | 5 | 6 |
17-
| 7 | 8 | 9 |
18-
Invalid move: 4 - 1 - 3 - 6
19-
Line 1 - 3 passes through key 2 which had not been selected in the pattern.
20-
21-
Invalid move: 4 - 1 - 9 - 2
22-
Line 1 - 9 passes through key 5 which had not been selected in the pattern.
23-
24-
Valid move: 2 - 4 - 1 - 3 - 6
25-
Line 1 - 3 is valid because it passes through key 2, which had been selected in the pattern
26-
27-
Valid move: 6 - 5 - 4 - 1 - 9 - 2
28-
Line 1 - 9 is valid because it passes through key 5, which had been selected in the pattern.
29-
30-
Example:
31-
Given m = 1, n = 1, return 9.
32-
33-
34-
*/
353
public class _351 {
364

375
public static class Solution1 {
@@ -50,9 +18,9 @@ public int numberOfPatterns(int m, int n) {
5018
visited = new boolean[10];
5119
int count = 0;
5220
count += dfs(1, 1, 0, m, n)
53-
* 4;//1,3,7,9 are symmetric, so we only need to use 1 to do it once and then multiply the result by 4
21+
* 4;//1,3,7,9 are symmetric, so we only need to use 1 to do it once and then multiply the result by 4
5422
count += dfs(2, 1, 0, m, n)
55-
* 4;//2,4,6,8 are symmetric, so we only need to use 1 to do it once and then multiply the result by 4
23+
* 4;//2,4,6,8 are symmetric, so we only need to use 1 to do it once and then multiply the result by 4
5624
count += dfs(5, 1, 0, m, n);
5725
return count;
5826
}

0 commit comments

Comments
 (0)