O(26) space complexity = O(1) space and O(n) Time complexity


  • 0
            short[] arr = new short[26];
    	for(int i = 0; i < s.length();i++){
    	   arr[s.charAt(i) - 97] += 1;
    	}
    	for(int i = 0; i < s.length(); i++){
    	   if(arr[s.charAt(i) - 97] == 1){
    			return i;
    		}
    	}
    	return -1;

Log in to reply
 

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