【笔试题】相似数

map,0和null不是一码事。
注意在线编程别System

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.*;

/**
 * @Author bennyrhys
 * @Date 2020-07-22 14:19
 * 样例:
 * 3 5
 * 1 10
 * 10 5
 * 22 3
 * 13
 * 思路:
 * 最少使用的技能次数,是最大范围对最高血量的攻击,覆盖范围为前提,否则递归不同范围杀以最高血量计数
 *
 */
public class T3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] sarr = in.nextLine().split(" ");

        char[] c1 = sarr[0].toCharArray();
        char[] c2 = sarr[1].toCharArray();
        f(c1,c2);
    }
    public static void f(char[] c1, char[] c2) {
//        if (c1.length != c1.length) {
//            return false;
//        }
        Map<Character, Integer> map =  new HashMap<Character, Integer>();
        for (int i = 0; i < c1.length; i++) {
            map.put(c1[i],(map.get(c1[i]) == null?1:map.get(c1[i])+1));
            map.put(c2[i],(map.get(c2[i]) == null?-1:map.get(c2[i])-1));
        }
//        if (map.isEmpty()) {
//            System.out.println("true");
//        }else {
//            System.out.println("false");
//        }
        for (int i = 0; i < c1.length; i++) {
            if (map.get(c1[i]) != 0) {
                System.out.println("false");
            }
        }
        System.out.println("true");
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43469680/article/details/107601465