Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.

PHOTO EMBED

Fri Apr 22 2022 14:36:10 GMT+0000 (Coordinated Universal Time)

Saved by @selvendhiran11 #java

class Solution {
    public int firstUniqChar(String s) {
       int len = s.length();
        int[] res = new int[26];
        for(int i=0;i<len;i++)
        {
            res[s.charAt(i)-'a']++;
        }
        for(int j=0;j<len;j++)
        {
            if(res[s.charAt(j)-'a'] == 1) return j;
        }
        return -1;
    }
}
content_copyCOPY

https://leetcode.com/explore/