1 class Solution:
 2     def minSteps(self, s: str, t: str) -> int:
 3         n = len(s)
 4         dic1 = {}
 5         for i in range(n):
 6             cur = s[i]
 7             if cur not in dic1:
 8                 dic1[cur] = 1
 9             else:
10                 dic1[cur] += 1
11         count = n
12         for j in range(n):
13             cur = t[j]
14             if cur in dic1 and dic1[cur] > 0:
15                 dic1[cur] -= 1
16                 count -= 1
17         return count

算法思路:hash,统计不同的字符个数。

posted on 2020-02-09 12:05  Sempron2800+  阅读(132)  评论(0编辑  收藏  举报