-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfind.py
More file actions
36 lines (32 loc) · 1.15 KB
/
find.py
File metadata and controls
36 lines (32 loc) · 1.15 KB
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
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
"""
# 100 pass - Simple problem of viewing the unmatched character iterating from a larger list
# Think of corner cases, when duplicate elements occurs, there occurs problem, solve it well before you think of the solution
# 100 pass - uses a separate list, try not using a separate list operation
s = list(s)
for ch in t:
if ch not in s:
return ch
else:
del s[s.index(ch)]
return -1
"""
"""
### Exor with same char negates itself so combining both the list and exoring each elements will result in the unique element
### Using EXOR
result = 0
for c in s+t:
result ^= ord(c)
return chr(result)
"""
### Nice logic - 100 pass
### Difference in the sum of hex all the characters
s_sum = sum([ord(i) for i in s])
t_sum = sum([ord(i) for i in t])
return chr(t_sum-s_sum)