-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniqueString.py
More file actions
32 lines (18 loc) · 746 Bytes
/
Copy pathuniqueString.py
File metadata and controls
32 lines (18 loc) · 746 Bytes
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
def isUnique(str):
checker = 0
strList = list(str)
for i in range(len(strList)):
# ord is used to find ASCII value of character in python
val = ord(strList[i]) - ord('a')
# if ASCII value of their differences was already added by shifting 1 as many times in bitwise
# representation of checker, then this time bitwise & will return true as at least one bit will be
# set high in bitwise and
if( checker & (1 << val) > 0):
return False
#left shift 1 and add it in bitwise representation of checker
checker = checker | (1 << val)
# checker |= (1 << val)
return True
print(isUnique("jayesh"))
print(isUnique("aaol"))
# print (1 << 0)