Leetcode 389. Find the Difference (Python)

You are 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.

Example 1:

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

Example 2:

Input: s = "", t = "y"
Output: "y"

Constraints:

  • 0 <= s.length <= 1000
  • t.length == s.length + 1
  • s and t consist of lowercase English letters.
class Solution(object):
    def findTheDifference(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: str
        """
        list1 = []
        list2 = []

        for i in s:
            list1.append(i)
            
        for j in t:
            list2.append(j)
            
        for k in list1:
            list2.remove(k)
            
        return list2[0]

你可能感兴趣的:(leetcode,大数据,算法,散列表,职场和发展)