File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Solutions/0389-find-the-difference Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 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 >  ; </p >
8+ <p ><strong class =" example " >Example 1:</strong ></p >
9+
10+ <pre >
11+ <strong >Input:</strong > s = " ; abcd" ; , t = " ; abcde" ;
12+ <strong >Output:</strong > " ; e" ;
13+ <strong >Explanation:</strong > ' ; e' ; 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 = " ;" ; , t = " ; y" ;
20+ <strong >Output:</strong > " ; y" ;
21+ </pre >
22+
23+ <p >  ; </p >
24+ <p ><strong >Constraints:</strong ></p >
25+
26+ <ul >
27+ <li><code>0 <= s.length <= 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 >
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments