Skip to content

Commit fbd174d

Browse files
committed
[LeetCode Sync] Runtime - 0 ms (100.00%), Memory - 19.7 MB (18.56%)
1 parent a145ae1 commit fbd174d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<p>Given an integer array <code>nums</code> where&nbsp;every element appears <strong>three times</strong> except for one, which appears <strong>exactly once</strong>. <em>Find the single element and return it</em>.</p>
2+
3+
<p>You must&nbsp;implement a solution with a linear runtime complexity and use&nbsp;only constant&nbsp;extra space.</p>
4+
5+
<p>&nbsp;</p>
6+
<p><strong class="example">Example 1:</strong></p>
7+
<pre><strong>Input:</strong> nums = [2,2,3,2]
8+
<strong>Output:</strong> 3
9+
</pre><p><strong class="example">Example 2:</strong></p>
10+
<pre><strong>Input:</strong> nums = [0,1,0,1,0,1,99]
11+
<strong>Output:</strong> 99
12+
</pre>
13+
<p>&nbsp;</p>
14+
<p><strong>Constraints:</strong></p>
15+
16+
<ul>
17+
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
18+
<li><code>-2<sup>31</sup> &lt;= nums[i] &lt;= 2<sup>31</sup> - 1</code></li>
19+
<li>Each element in <code>nums</code> appears exactly <strong>three times</strong> except for one element which appears <strong>once</strong>.</li>
20+
</ul>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Solution:
2+
def singleNumber(self, nums: List[int]) -> int:
3+
count = Counter(nums)
4+
return next(key for key, value in count.items() if value == 1)

0 commit comments

Comments
 (0)