C# Solution


  • 0
    M
    public int FirstUniqChar(string s) {
        int[] chars = new int[26];
        for (int i = 0; i < s.Length; i++)
        {
            chars[s[i] - 'a']++;
        }
        
        for (int i = 0; i < s.Length; i++)
        {
            if (chars[s[i] - 'a'] == 1) return i;  
        }
        
        return -1;
    }

  • 0
    V

    Please format your code properly


  • 0
    M

    Thank you Vikram for your feedback. I fixed the format problem.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.