A Journey 2 Eternity

Check all characters in string are unique

Posted on: July 13, 2012

bool IsUniqueChars(const string &str)
{
	if(str.length() > 256) return false;

	bool char_set[256];
	for (unsigned int i = 0; i < 256; i++)
	{
		char_set[i] = false;
	}

	for (unsigned int i = 0; i < str.length(); i++)
	{
		int val = str.at(i);
		if(char_set[val]) return false;
		char_set[val] = true;
	}

	return true;
}
Advertisements
Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Pages

Categories

July 2012
M T W T F S S
« Jun   Aug »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Blog Stats

  • 27,486 hits
%d bloggers like this: