严氏北美IT公司面试真题汇总和解答论坛
Would you like to react to this message? Create an account in a few clicks or log in to continue.

FirstUniqueCharacterInAString 串中第一个出现的唯一字符

Go down

FirstUniqueCharacterInAString  串中第一个出现的唯一字符 Empty FirstUniqueCharacterInAString 串中第一个出现的唯一字符

Post by Admin Sun Oct 22, 2017 2:30 pm

public static int firstUniqChar(String s) {
           int freq [] = new int[26];
           for(int i = 0; i < s.length(); i ++)
               freq [s.charAt(i) - 'a'] ++;
           for(int i = 0; i < s.length(); i ++)
               if(freq [s.charAt(i) - 'a'] == 1)
                   return i;
           return -1;
       }

Admin
Admin

Posts : 124
Join date : 2017-10-21

https://csinterviewquestions.forumotion.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum