Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions problems/leet_389.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://leetcode.com/problems/find-the-difference/
# Runtime: 36 ms, faster than 68.64% of Python3 online submissions for Find the Difference.


class Solution:
def findTheDifference(self, s: str, t: str) -> str:
alpha = dict()
for each_s in s:
if each_s not in alpha:
alpha[each_s] = 1
else:
alpha[each_s]+=1
for each_t in t:
if each_t in alpha:
alpha[each_t] -=1
else:
alpha[each_t] = 1
string=""
for key,value in alpha.items():
if(value==1 or value==-1):
string+=key
print(string)
return string


s = Solution()
print(s.findTheDifference("abcd", "abcde"))