|
1 | 1 | package com.fishercoder.solutions;
|
2 | 2 |
|
3 |
| -/** |
4 |
| - * 26. Remove Duplicates from Sorted Array |
5 |
| - * |
6 |
| - * Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. |
7 |
| - * Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. |
8 |
| - * |
9 |
| - * Example 1: |
10 |
| - * Given nums = [1,1,2], |
11 |
| - * Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. |
12 |
| - * It doesn't matter what you leave beyond the returned length. |
13 |
| - * |
14 |
| - * Example 2: |
15 |
| - * Given nums = [0,0,1,1,1,2,2,3,3,4], |
16 |
| - * Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively. |
17 |
| - * It doesn't matter what values are set beyond the returned length. |
18 |
| - * |
19 |
| - * Clarification: |
20 |
| - * Confused why the returned value is an integer but your answer is an array? |
21 |
| - * Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well. |
22 |
| - * Internally you can think of this: |
23 |
| - * // nums is passed in by reference. (i.e., without making a copy) |
24 |
| - * int len = removeDuplicates(nums); |
25 |
| - * |
26 |
| - * // any modification to nums in your function would be known by the caller. |
27 |
| - * // using the length returned by your function, it prints the first len elements. |
28 |
| - * for (int i = 0; i < len; i++) { |
29 |
| - * print(nums[i]); |
30 |
| - * } |
31 |
| - * */ |
32 |
| - |
33 | 3 | public class _26 {
|
34 | 4 |
|
35 | 5 | public static class Solution1 {
|
|
0 commit comments