Small and fast C solution with pointer arithmetic


  • 0
    V
    int firstUniqChar(char * s)
    {
    	int tbl[26] = {0};
    	char * t;
    	
    	for(t = s; *t; ++t)
    		++tbl['z' - *t];
    	
    	for(t = s; *t; ++t)
    		if (1 == tbl['z' - *t])
    			return t - s;
    
    	return -1;
    }
    

Log in to reply
 

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