第一题 public static String getRes(String s){ String[] strs = s.split(" "); if (strs[0].equals(strs[1])) return "Yes"; int preIndex=0; int nextIndex=0; int count=0; for (int i=0; i<strs[0].length(); i++){ if (strs[0].charAt(i)==strs[1].charAt(i)) continue; if (strs[0].charAt(i)!=strs[1].charAt(i)&;&;count==0){ preIndex=i; count++; }else if (strs[0].charAt(i)!=strs[1].charAt(i)&;&;count==1){ count++; nextIndex=i; boolean isRes = strs[0].charAt(preIndex)==strs[1].charAt(nextIndex) &;&; strs[0].charAt(nextIndex)==strs[1].charAt(preIndex); if(!isRes) return "No"; }else{ return "No"; } } if (count<2) return "No"; return "Yes"; } }
点赞 评论

相关推荐

牛客网
牛客企业服务