so clear solution,you should see it.


  • 0
    J
    public class Solution {
      public static  int firstUniqChar(String s) {
    		char[] c = s.toCharArray();
    		List<Character> l = new ArrayList<>();
    		for(int i=0;i<c.length;i++){
    			int t = i;
    			if(s.lastIndexOf(c[i])==t&&!l.contains(c[i])){
    				return i;
    			}	
    			l.add(c[i]);
    		}
    		return -1;
    	}
    
    }
    

  • 0
    E

    @justcodeit time complexity is O(n^2)


Log in to reply
 

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