forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1056.java
37 lines (34 loc) · 940 Bytes
/
_1056.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _1056 {
public static class Solution1 {
Map<Integer, Integer> map = new HashMap<Integer, Integer>() {
{
put(0, 0);
put(1, 1);
put(8, 8);
put(6, 9);
put(9, 6);
}
};
public boolean confusingNumber(int N) {
if (N == 0) {
return false;
}
int newNumber = 0;
int originalN = N;
while (N != 0) {
newNumber *= 10;
int digit = N % 10;
if (!map.containsKey(digit)) {
return false;
}
digit = map.get(digit);
newNumber += digit;
N /= 10;
}
return newNumber != originalN;
}
}
}