剑指offer(三十八)之第一个只出现一次的字符位置

前端之家收集整理的这篇文章主要介绍了剑指offer(三十八)之第一个只出现一次的字符位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
题目描写

在1个字符串(1<=字符串长度<=10000,全部由字母组成)中找到第1个只出现1次的字符的位置。若为空串,返回⑴。位置索引从0开始

思路分析:

1.先把字符串存到字节数组当中

     2.设置1个标志位,再用两个FOR循环

<span style="font-family:SimSun;font-size:24px;">public class Solution { public int FirstNotRepeatingChar(String str) { if(str.length()==0){ return ⑴; } char []c=new char[10000]; for(int i=0;i<str.length();i++){ c[i]=str.charAt(i); } for(int i=0;i<str.length();i++){ int flag=0; for(int j=0;j<str.length();j++){ if(c[i]==c[j]){ flag++; } } if(flag==1){ return i; } } return ⑴; } }</span>


猜你在找的PHP相关文章