Skip to content

Commit d8ffafa

Browse files
committed
[LeetCode Sync] Runtime - 3 ms (51.44%), Memory - 18 MB (25.11%)
1 parent e0d8d73 commit d8ffafa

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<p>You are given two strings <code>s</code> and <code>t</code>.</p>
2+
3+
<p>String <code>t</code> is generated by random shuffling string <code>s</code> and then add one more letter at a random position.</p>
4+
5+
<p>Return the letter that was added to <code>t</code>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<pre>
11+
<strong>Input:</strong> s = &quot;abcd&quot;, t = &quot;abcde&quot;
12+
<strong>Output:</strong> &quot;e&quot;
13+
<strong>Explanation:</strong> &#39;e&#39; is the letter that was added.
14+
</pre>
15+
16+
<p><strong class="example">Example 2:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> s = &quot;&quot;, t = &quot;y&quot;
20+
<strong>Output:</strong> &quot;y&quot;
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Constraints:</strong></p>
25+
26+
<ul>
27+
<li><code>0 &lt;= s.length &lt;= 1000</code></li>
28+
<li><code>t.length == s.length + 1</code></li>
29+
<li><code>s</code> and <code>t</code> consist of lowercase English letters.</li>
30+
</ul>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def findTheDifference(self, s: str, t: str) -> str:
3+
count = Counter(s)
4+
for char in t:
5+
count[char] -= 1
6+
if count[char] < 0:
7+
return char
8+

0 commit comments

Comments
 (0)