当前位置: 代码迷 >> 综合 >> leetcode-Algorithms-1056|易混淆数
  详细解决方案

leetcode-Algorithms-1056|易混淆数

热度:71   发布时间:2023-12-12 11:58:07.0

原题

在这里插入图片描述

思路

注意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;}
}