We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 6a481cb + 153bf19 commit 0aaf8c5Copy full SHA for 0aaf8c5
String/AllUniques.cpp
@@ -0,0 +1,46 @@
1
+// An algorithm to check if a string has all unique characters.
2
+// Sample Input-1: Hello
3
+// Sample Output-2: All Characters are not Unique
4
+
5
+// Sample Input-1: World
6
+// Sample Output-2: All Characters are Unique
7
8
9
+#include<bits/stdc++.h>
10
+using namespace std;
11
12
+// time complexity = O(n)
13
+// 128-character alphabet set
14
+bool isAllUnique(string st)
15
+{
16
+ if(st.length()>128)
17
+ return false;
18
19
+ // initialize vector to zero flag
20
+ vector<bool> char_set(128,0);
21
+ int val;
22
+ for (int i = 0; i < st.length(); i++)
23
+ {
24
+ val = st.at(i);
25
+ if(char_set[val])
26
27
+ // already found this character
28
29
+ }
30
31
+ char_set[val] = true;
32
33
+ return true;
34
+}
35
36
+int main()
37
38
+ string st;
39
+ getline(cin,st);
40
+ if(isAllUnique(st)){
41
+ cout<<"All Characters are Unique"<<endl;
42
+ }else{
43
+ cout<<"All Characters are not Unique"<<endl;
44
45
+ return 0;
46
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments