-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathIsUnique.cpp
More file actions
38 lines (30 loc) · 732 Bytes
/
IsUnique.cpp
File metadata and controls
38 lines (30 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <string>
using namespace std;
/*
Implement an algorithm to determine if a string has all unique characters.
Notes:
ASCII is a 7-bit code, representing 128 different characters.
Ques to Ask:
Is string ASCII or Unicode ?
We assume ASCII for this example.
*/
bool isDupUsingHashTable( string input ) {
if( input.length() > 128 ) {
return true;
}
for(int i=0;i<input.length();i++){
for(int j=i+1;j<input.length();j++){
if(input[i]==input[j])
return true;
}
}
return false;
}
int main() {
string s = "Not Duplicate";
string s1 = "Not Duplicae";
cout<< isDupUsingHashTable( s ) << endl;
cout<< isDupUsingHashTable( s1 ) << endl;
return 0;
}