标签:har 判断 完全 是否一致 for 遍历 字符串 col oar
思路:
1,遍历第一个字符串,统计各个字符出现的次数
2,遍历第二个字符串,统计各个字符出现的次数
3,判断两个字符串对应字符出现的次数是否一致
public class OptMain { public static void main(String[] args) { isSame("sdfajsodafisaf","sdfajsodafisfa"); } private static void isSame(String one ,String two){ if(one.length() != two.length()){ System.out.println("false...."); return; } int[] oneArr = new int[26]; int[] twoArr = new int[26]; for (char c : one.toCharArray()) { int i = c - ‘a‘; oneArr[i]++; } for (char c : two.toCharArray()) { int i = c - ‘a‘; twoArr[i]++; } int loop = Math.min(oneArr.length,one.length()); for (int i = 0; i < loop; i++) { if(oneArr[i] != twoArr[i]){ System.out.println("不匹配...."); return; } } System.out.println("匹配"); } }
标签:har 判断 完全 是否一致 for 遍历 字符串 col oar
原文地址:https://www.cnblogs.com/dongma/p/13168521.html