Skip to content

Commit 50b9344

Browse files
committed
[LeetCode Sync] Runtime - 0 ms (100.00%), Memory - 17.9 MB (40.05%)
1 parent 9be27f2 commit 50b9344

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<p>A <strong>sentence</strong> is a string of single-space separated words where each word consists only of lowercase letters.</p>
2+
3+
<p>A word is <strong>uncommon</strong> if it appears exactly once in one of the sentences, and <strong>does not appear</strong> in the other sentence.</p>
4+
5+
<p>Given two <strong>sentences</strong> <code>s1</code> and <code>s2</code>, return <em>a list of all the <strong>uncommon words</strong></em>. You may return the answer in <strong>any order</strong>.</p>
6+
7+
<p>&nbsp;</p>
8+
<p><strong class="example">Example 1:</strong></p>
9+
10+
<div class="example-block">
11+
<p><strong>Input:</strong> <span class="example-io">s1 = &quot;this apple is sweet&quot;, s2 = &quot;this apple is sour&quot;</span></p>
12+
13+
<p><strong>Output:</strong> <span class="example-io">[&quot;sweet&quot;,&quot;sour&quot;]</span></p>
14+
15+
<p><strong>Explanation:</strong></p>
16+
17+
<p>The word <code>&quot;sweet&quot;</code> appears only in <code>s1</code>, while the word <code>&quot;sour&quot;</code> appears only in <code>s2</code>.</p>
18+
</div>
19+
20+
<p><strong class="example">Example 2:</strong></p>
21+
22+
<div class="example-block">
23+
<p><strong>Input:</strong> <span class="example-io">s1 = &quot;apple apple&quot;, s2 = &quot;banana&quot;</span></p>
24+
25+
<p><strong>Output:</strong> <span class="example-io">[&quot;banana&quot;]</span></p>
26+
</div>
27+
28+
<p>&nbsp;</p>
29+
<p><strong>Constraints:</strong></p>
30+
31+
<ul>
32+
<li><code>1 &lt;= s1.length, s2.length &lt;= 200</code></li>
33+
<li><code>s1</code> and <code>s2</code> consist of lowercase English letters and spaces.</li>
34+
<li><code>s1</code> and <code>s2</code> do not have leading or trailing spaces.</li>
35+
<li>All the words in <code>s1</code> and <code>s2</code> are separated by a single space.</li>
36+
</ul>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Solution:
2+
def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:
3+
count = Counter((s1 + " " + s2).split())
4+
return [item for item, num in count.items() if num == 1]

0 commit comments

Comments
 (0)