Skip to content

Commit 8006d60

Browse files
refactor 1056
1 parent 09953b0 commit 8006d60

File tree

1 file changed

+8
-45
lines changed

1 file changed

+8
-45
lines changed

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

+8-45
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,16 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6-
/**
7-
* 1056. Confusing Number
8-
*
9-
* Given a number N, return true if and only if it is a confusing number, which satisfies the following condition:
10-
* We can rotate digits by 180 degrees to form new digits. When 0, 1, 6, 8, 9 are rotated 180 degrees,
11-
* they become 0, 1, 9, 8, 6 respectively. When 2, 3, 4, 5 and 7 are rotated 180 degrees,
12-
* they become invalid. A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.
13-
*
14-
* Example 1:
15-
* Input: 6
16-
* Output: true
17-
* Explanation:
18-
* We get 9 after rotating 6, 9 is a valid number and 9!=6.
19-
*
20-
*
21-
* Example 2:
22-
* Input: 89
23-
* Output: true
24-
* Explanation:
25-
* We get 68 after rotating 89, 86 is a valid number and 86!=89.
26-
*
27-
*
28-
* Example 3:
29-
* Input: 11
30-
* Output: false
31-
* Explanation:
32-
* We get 11 after rotating 11, 11 is a valid number but the value remains the same, thus 11 is not a confusing number.
33-
*
34-
* Example 4:
35-
* Input: 25
36-
* Output: false
37-
* Explanation:
38-
* We get an invalid number after rotating 25.
39-
*
40-
* Note:
41-
*
42-
* 0 <= N <= 10^9
43-
* After the rotation we can ignore leading zeros, for example if after rotation we have 0008 then this number is considered as just 8.*/
446
public class _1056 {
457
public static class Solution1 {
46-
Map<Integer, Integer> map = new HashMap<Integer, Integer>() {{
47-
put(0, 0);
48-
put(1, 1);
49-
put(8, 8);
50-
put(6, 9);
51-
put(9, 6);
52-
}
8+
Map<Integer, Integer> map = new HashMap<Integer, Integer>() {
9+
{
10+
put(0, 0);
11+
put(1, 1);
12+
put(8, 8);
13+
put(6, 9);
14+
put(9, 6);
15+
}
5316
};
5417

5518
public boolean confusingNumber(int N) {

0 commit comments

Comments
 (0)