Skip to content

Instantly share code, notes, and snippets.

@mogutou1214
Created May 15, 2013 04:50
Show Gist options
  • Save mogutou1214/5581704 to your computer and use it in GitHub Desktop.
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?
/*
* 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