[LeetCode] #389. Find the Difference

Fatboy Slim
1 min readMar 14, 2020

--

Environment: Python 3.7

Key technique: “count” and “not in” function

Example:

Input:
s = "abcd"
t = "abcde"
Output:
e
Explanation:
'e' is the letter that was added.

Analysis:

I get some miss understanding when try to solve it. This problem find added string and does not find the string never showing.

Solution:

class Solution:
def findTheDifference(self, s: str, t: str) -> str:
for i in t:
if(i not in s or s.count(i)!=t.count(i)):
diff=i
return diff

Submitted result:

Reference:

https://leetcode.com/problems/find-the-difference/discuss/472745/Simple-Python-(98-100)

--

--

Fatboy Slim
Fatboy Slim

Written by Fatboy Slim

Interesting in any computer science.

No responses yet