[简单] 387. 字符串中的第一个唯一字符
作者:互联网
https://leetcode-cn.com/problems/first-unique-character-in-a-string/
一直都写着没有灵魂的代码
class Solution { public int firstUniqChar(String s) { if(s.length() == 1) { return 0; } int ret = -1; Set<String> st = new HashSet<>(); for (int i = 0; i < s.length(); i++) { String ch = String.valueOf(s.charAt(i)); if(!st.contains(ch)) { System.out.println("check : " + ch); int a = s.indexOf(ch, i + 1); if(a == -1 || (i == s.length() - 1)) { ret = i; break; } st.add(ch); } } st.clear(); return ret; } }View Code
标签:字符,ch,String,int,ret,st,length,387,字符串 来源: https://www.cnblogs.com/chenxiaomai/p/16100120.html