Created
May 15, 2013 04:50
-
-
Save mogutou1214/5581704 to your computer and use it in GitHub Desktop.
Careercup1.1: Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* test.cpp | |
*Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures? | |
* Created on: 2013-5-4 | |
* Author: Fred | |
*/ | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
bool chk_unique(string str){ | |
int i,j; | |
int length = str.length(); | |
for(i=0;i<length;i++){ | |
for(j=i+1;j<length;j++) | |
if(str[i]==str[j]) return false; | |
} | |
return true; | |
} | |
int main() { | |
string test_str1="asloiwzxc"; | |
cout<< chk_unique(test_str1); | |
string test_str2="slsoialow"; | |
cout<< chk_unique(test_str2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment