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.
0 parents commit 4a43fa0Copy full SHA for 4a43fa0
Arrays_And_Strings/Is_Unique.py
@@ -0,0 +1,32 @@
1
+'''
2
+Is Unique: Implement an algorithm to determine if a string has all unique characters. What if you
3
+cannot use additional data structures?
4
+Hints: #44, #117, #132
5
+
6
7
8
+PS: Assuming String to be 256 unicoded
9
10
+from unicodedata import name
11
12
13
+def is_Unique(string):
14
15
+ #edge case
16
+ if (len(string) == 1):
17
+ return True
18
19
+ unique_char = [False] * 256
20
21
+ for char in string:
22
+ if(unique_char[ord(char)] == False):
23
+ unique_char[ord(char)] = True
24
+ else:
25
+ return False
26
27
28
29
+if __name__ == '__main__':
30
+ str1 = input("Enter String >> ")
31
+ answer = is_Unique(str1.strip())
32
+ print(answer)
0 commit comments