-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy path1-1.cpp
41 lines (37 loc) · 858 Bytes
/
1-1.cpp
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
39
40
41
#include <iostream>
#include <string>
using namespace std;
class Solution{
public:
bool isunique1(string str){
for (int i=0;i<str.size();i++){
for (int j=0;j<str.size();j++){
if (i!=j && str[i]==str[j]){
return false;
}
}
}
return true;
}
bool isunique2(string str){
bool* A = new bool[256];
for (int i=0;i<str.size();i++){
if (A[str[i]]==true){
return false;
}else{
A[str[i]]=true;
}
}
return true;
}
};
int main(){
Solution sol;
string str = "asdafajkbczmvbus";
//cin >> str;
cout << str << ": ";
sol.isunique1(str) ? (cout << "true" << endl) : (cout << "false" << endl);
cout << str<< ": ";
sol.isunique2(str) ? (cout << "true" << endl) : (cout << "false" << endl);
return 0;
}