File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 9
9
| 13 | [ Roman To Integer] ( https://leetcode.com/problems/roman-to-integer/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RomanToInteger.java ) |
10
10
| 14 | [ Longest Common Prefix] ( https://leetcode.com/problems/longest-common-prefix/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/LongestCommonPrefix.java ) |
11
11
| 20 | [ ValidParentheses] ( https://leetcode.com/problems/valid-parentheses/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ValidParentheses.java ) |
12
- | 21 | [ Merge 2 Sorted Lists] ( https://leetcode.com/problems/merge-two-sorted-lists/ ) | Easy | |
13
- | 2 | [ ] ( ) | Easy | |
12
+ | 21 | [ Merge 2 Sorted Lists] ( https://leetcode.com/problems/merge-two-sorted-lists/ ) | Easy | [ ![ Java ] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/Merge2SortedLists.java ) |
13
+ | 26 | [ remove Duplicates From Sorted Array ] ( https://leetcode.com/problems/remove-duplicates-from-sorted-array/ ) | Easy | |
14
14
| 2 | [ ] ( ) | Easy | |
15
15
| 2 | [ ] ( ) | Easy | |
16
16
| 2 | [ ] ( ) | Easy | |
Original file line number Diff line number Diff line change
1
+ public class RemoveDuplicatesFromSortedArray {
2
+ public int removeDuplicates (int [] array ) {
3
+ if (array .length == 0 ) {
4
+ return 0 ;
5
+ }
6
+
7
+ int position = 1 ;
8
+ for (int index = 1 , previouslyEncountered = array [0 ]; index < array .length ; index ++) {
9
+ if (array [index ] != previouslyEncountered ) {
10
+ array [position ++] = array [index ];
11
+ previouslyEncountered = array [index ];
12
+ }
13
+ }
14
+
15
+ return position ;
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments