码迷,mamicode.com
首页 > 其他好文 > 详细

字符串中出现一次的字符出现的位置

时间:2018-08-24 20:43:19      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:code   har   ring   first   temp   stun   tin   相同   indexof   

public int firstUniqChar(String s) {
if(s.length()<=1){
return (s.length()==0)?-1:0;//特殊情况长度为1 或者0
}
int index=-1;
for(int i=0;i<s.length();i++){//判断字符第一次出现的位置是否和最后一次出现的位置相同
String temp=s.charAt(i)+"";
int st=s.indexOf(temp);
int ed=s.lastIndexOf(temp);
if(st-ed==0){
index=i;
break;

      }     

字符串中出现一次的字符出现的位置

标签:code   har   ring   first   temp   stun   tin   相同   indexof   

原文地址:http://blog.51cto.com/13919712/2164084

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!