Loading...

09-25 leetcode 0389

链接 389. Find the Difference

题目

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.

题解

直接暴力求解

1
2
3
4
5
6
7
8
9
10
from collections import Counter


class Solution:
def findTheDifference(self, s: str, t: str) -> str:
counter_s, counter_t = Counter(s), Counter(t)
for key, value in counter_t.items():
if key not in counter_s or value != counter_s[key]:
return key
return ""

Comment