You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/com/fishercoder/solutions/_351.java
+2-34Lines changed: 2 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -1,37 +1,5 @@
1
1
packagecom.fishercoder.solutions;
2
2
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
-
*/
35
3
publicclass_351 {
36
4
37
5
publicstaticclassSolution1 {
@@ -50,9 +18,9 @@ public int numberOfPatterns(int m, int n) {
50
18
visited = newboolean[10];
51
19
intcount = 0;
52
20
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
54
22
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
0 commit comments