在一个字符串中找到第一个只出现一次的字符(JAVA实现)

来源:互联网 发布:div如何调用js函数 编辑:程序博客网 时间:2024/05/16 12:06
/** * @author PLA   * 在一个字符串中找到第一个只出现一次的字符 */public static void main(String[] args) {String s = "dtoghohronogddddew";int judge = find(s);if(judge!=-1) System.out.println(s.charAt(judge));elseSystem.out.println("There is no number adaptability!");}private static int find(String s) {// TODO Auto-generated method stubchar[] ch = s.toCharArray();int[] count = new int[26];for(char c:ch){count[c-'a']++;}for(int i=0;i<count.length;i++){if(count[s.charAt(i)-'a']==1){return i;}}return -1;}

0 0