Q48 First Unique Character in a String - LeetCode

PHOTO EMBED

Mon Jan 30 2023 13:19:40 GMT+0000 (Coordinated Universal Time)

Saved by @Ayush_dabas07

class Solution {
    public int firstUniqChar(String s) {
        HashMap<Character,Integer> map = new HashMap<>();

        for(char ch : s.toCharArray())
        map.put(ch , map.getOrDefault(ch,0)+1);
            
        
        
        for(int i = 0 ; i < s.length() ;i++){
            char ch = s.charAt(i);
            if(map.get(ch)==1) return i;
        }
        

        return -1;
    }
}
content_copyCOPY

https://leetcode.com/problems/first-unique-character-in-a-string/submissions/888093225/