Skip to content

Commit 596a5d1

Browse files
committed
chore: sync automated leetcode submissions with Runtime - 0 ms (100.00%), Memory - 2.2 MB (100.00%)
1 parent 1c001a6 commit 596a5d1

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<p>You are given an integer array <code>nums</code> with the following properties:</p>
2+
3+
<ul>
4+
<li><code>nums.length == 2 * n</code>.</li>
5+
<li><code>nums</code> contains <code>n + 1</code> <strong>unique</strong> elements.</li>
6+
<li>Exactly one element of <code>nums</code> is repeated <code>n</code> times.</li>
7+
</ul>
8+
9+
<p>Return <em>the element that is repeated </em><code>n</code><em> times</em>.</p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
<pre><strong>Input:</strong> nums = [1,2,3,3]
14+
<strong>Output:</strong> 3
15+
</pre><p><strong class="example">Example 2:</strong></p>
16+
<pre><strong>Input:</strong> nums = [2,1,2,5,3,2]
17+
<strong>Output:</strong> 2
18+
</pre><p><strong class="example">Example 3:</strong></p>
19+
<pre><strong>Input:</strong> nums = [5,1,5,2,5,3,5,4]
20+
<strong>Output:</strong> 5
21+
</pre>
22+
<p>&nbsp;</p>
23+
<p><strong>Constraints:</strong></p>
24+
25+
<ul>
26+
<li><code>2 &lt;= n &lt;= 5000</code></li>
27+
<li><code>nums.length == 2 * n</code></li>
28+
<li><code>0 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
29+
<li><code>nums</code> contains <code>n + 1</code> <strong>unique</strong> elements and one of them is repeated exactly <code>n</code> times.</li>
30+
</ul>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
impl Solution {
2+
pub fn repeated_n_times(nums: Vec<i32>) -> i32 {
3+
let n = nums.len();
4+
5+
for distance in 1..=3 {
6+
for i in 0..(n - distance) {
7+
if nums[i] == nums[i + distance] {
8+
return nums[i];
9+
}
10+
}
11+
}
12+
-1
13+
}
14+
}

0 commit comments

Comments
 (0)