赞
踩
示例 1:
s = "leetcode"
返回 0.
s = "loveleetcode",
返回 2.
JAVA 代码:
class Solution { public int firstUniqChar(String s) { int index = s.length(); for (char k = 'a'; k <= 'z'; k++) { int p1 = s.indexOf(k);// -1 不存在 int p2 = s.lastIndexOf(k); if (p1 == p2 && p1 != -1) { index = Math.min(index, p1); } } if (index == s.length()) { return -1; } return index; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。