cracking the coding interview No1.1



1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannnot use additional data structures?


bool isUnique(char *str)
{
	int hash[256];
	memset(hash,0,sizeof(hash));

	if (str == NULL)
	{
		return false;
	}

	while (*str != '\0')
	{
		if(hash[*str])
		{
			return false;
		}
		hash[*str] = 1;	
		str++;
	}

	return true;
}

你可能感兴趣的:(cracking the coding interview No1.1)