Skip to content

Commit 4a43fa0

Browse files
Is_Unique Completed
0 parents  commit 4a43fa0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Arrays_And_Strings/Is_Unique.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
return True
28+
29+
if __name__ == '__main__':
30+
str1 = input("Enter String >> ")
31+
answer = is_Unique(str1.strip())
32+
print(answer)

0 commit comments

Comments
 (0)