Last active
December 14, 2015 02:29
-
-
Save ThunderXu/5013616 to your computer and use it in GitHub Desktop.
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
#include "stdafx.h" | |
#include <string> | |
#include <iostream> | |
bool HasDuplication(std::string); | |
int main() | |
{ | |
using namespace std; | |
string str; | |
cin>>str; | |
bool res = HasDuplication(str); | |
if(res) | |
{ | |
cout<<"Has Duplication"<<endl; | |
} | |
else | |
{ | |
cout<<"Has All unique characters"<<endl; | |
} | |
return 0; | |
} | |
bool HasDuplication(std::string str) | |
{ | |
for(int i=0,size=str.size();i<size;i++) | |
{ | |
for(int j=i+1;j<size;j++) | |
{ | |
if(str[i]==str[j]) | |
{ | |
return true; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment