diff options
author | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
---|---|---|
committer | jack <[email protected]> | 2024-06-14 13:13:15 -0600 |
commit | d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa (patch) | |
tree | 96df922dae2a5073d9a50ea70c7aae6aa37e3ebe /find_difference.py | |
download | leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.tar.gz leetcode-d343a3b18dbaca9297d4f7b2280c4a16f0a5c8aa.zip |
initial
Diffstat (limited to 'find_difference.py')
-rw-r--r-- | find_difference.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/find_difference.py b/find_difference.py new file mode 100644 index 0000000..f0b26a6 --- /dev/null +++ b/find_difference.py @@ -0,0 +1,23 @@ +# 389. Find the Difference + +""" +given two strings 's' and 't'. string 't' is generated by random shuffling +string 's' and then add one more letter at a random position. return the +letter that was added to 't'. +""" + + +class Solution(object): + def findTheDifference(self, s, t): + ans = 0 + for i in s: + ans ^= ord(i) + for i in t: + ans ^= ord(i) + return chr(ans) + + +if __name__ == "__main__": + obj = Solution() + print(obj.findTheDifference("abcd", "abcde")) # expect: e + print(obj.findTheDifference("", "y")) # expect: y |