原题
思路
注意916和619
代码
package leetcode.Algorithms;import java.util.HashMap;public class Solution_1065 {
public static void main(String[] args) {
System.out.println(confusingNumber(916));}public static boolean confusingNumber(int n) {
boolean confusingNumber = false;char[] chars = String.valueOf(n).toCharArray();HashMap<Character, Character> map = new HashMap<Character, Character>() {
{
put('0', '0');put('1', '1');put('6', '9');put('8', '8');put('9', '6');}};StringBuilder sctringBuilder = new StringBuilder();for (char c : chars) {
if (c == ('2') || c == ('3') || c == ('4') || c == ('5') || c == ('7')) {
confusingNumber = false;break;} else {
sctringBuilder.append(map.get(c).toString());}}if (sctringBuilder.length()==String.valueOf(n).length()){
if (Integer.valueOf(sctringBuilder.reverse().toString()) != n) {
confusingNumber = true;}}return confusingNumber;}
}