Skip to content

Commit d2f3308

Browse files
duplicate in o(1) space and o(n^2) time
1 parent 6007708 commit d2f3308

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

1-Array-And-String/IsUnique.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ bool isDupUsingHashTable( string input ) {
2020
return true;
2121
}
2222

23-
bool map[ 128 ] = { false };
24-
for( int i=0; i < input.length(); i++ ) {
25-
if( map[ input[ i ] ] == true )
26-
return true;
27-
else
28-
map[ input[ i ] ]= true;
23+
for(int i=0;i<input.length();i++){
24+
for(int j=i+1;j<input.length();j++){
25+
if(input[i]==input[j])
26+
return true;
27+
}
2928
}
3029
return false;
3130
}

0 commit comments

Comments
 (0)