Skip to content

Commit d01f600

Browse files
committed
Added README.md file for Remove Duplicates from Sorted Array
1 parent da60a22 commit d01f600

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

  • 26-remove-duplicates-from-sorted-array
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<h2><a href="https://leetcode.com/problems/remove-duplicates-from-sorted-array">Remove Duplicates from Sorted Array</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>Given an integer array <code>nums</code> sorted in <strong>non-decreasing order</strong>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank"><strong>in-place</strong></a> such that each unique element appears only <strong>once</strong>. The <strong>relative order</strong> of the elements should be kept the <strong>same</strong>.</p>
2+
3+
<p>Consider the number of <em>unique elements</em> in&nbsp;<code>nums</code> to be <code>k<strong>​​​​​​​</strong></code>​​​​​​​. <meta charset="UTF-8" />After removing duplicates, return the number of unique elements&nbsp;<code>k</code>.</p>
4+
5+
<p><meta charset="UTF-8" />The first&nbsp;<code>k</code>&nbsp;elements of&nbsp;<code>nums</code>&nbsp;should contain the unique numbers in <strong>sorted order</strong>. The remaining elements beyond index&nbsp;<code>k - 1</code>&nbsp;can be ignored.</p>
6+
7+
<p><strong>Custom Judge:</strong></p>
8+
9+
<p>The judge will test your solution with the following code:</p>
10+
11+
<pre>
12+
int[] nums = [...]; // Input array
13+
int[] expectedNums = [...]; // The expected answer with correct length
14+
15+
int k = removeDuplicates(nums); // Calls your implementation
16+
17+
assert k == expectedNums.length;
18+
for (int i = 0; i &lt; k; i++) {
19+
assert nums[i] == expectedNums[i];
20+
}
21+
</pre>
22+
23+
<p>If all assertions pass, then your solution will be <strong>accepted</strong>.</p>
24+
25+
<p>&nbsp;</p>
26+
<p><strong class="example">Example 1:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> nums = [1,1,2]
30+
<strong>Output:</strong> 2, nums = [1,2,_]
31+
<strong>Explanation:</strong> Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively.
32+
It does not matter what you leave beyond the returned k (hence they are underscores).
33+
</pre>
34+
35+
<p><strong class="example">Example 2:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> nums = [0,0,1,1,1,2,2,3,3,4]
39+
<strong>Output:</strong> 5, nums = [0,1,2,3,4,_,_,_,_,_]
40+
<strong>Explanation:</strong> Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.
41+
It does not matter what you leave beyond the returned k (hence they are underscores).
42+
</pre>
43+
44+
<p>&nbsp;</p>
45+
<p><strong>Constraints:</strong></p>
46+
47+
<ul>
48+
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
49+
<li><code>-100 &lt;= nums[i] &lt;= 100</code></li>
50+
<li><code>nums</code> is sorted in <strong>non-decreasing</strong> order.</li>
51+
</ul>

0 commit comments

Comments
 (0)