`
hufeng
  • 浏览: 100911 次
  • 性别: Icon_minigender_1
  • 来自: 江西
社区版块
存档分类
最新评论

找出字符串中第一个没有重复出现的字符

阅读更多
public class QueryFirst {
	public static void main(String[] args) {
		String str = "aabbc";
		System.out.println(getFirst(str));
	}
	public static String getFirst(String str){
		char c[] = str.toCharArray();
		int n[] = new int[c.length];
		for (int i = 0; i < c.length; i++) {
			
			for (int j =0; j < c.length; j++) {
				if(c[j] == c[i]){
					n[i]++;
				}
			}
		}
		int index = -1;
		for (int i = 0; i < n.length; i++) {
			if(n[i] == 1){
				index = i;break;
			}
		}
		for (int i = 0; i < n.length; i++) {
			System.out.println(n[i]);
		}
		if(index == -1)return null;
		return String.valueOf(c[index]);
	}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics