Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5e95964

Browse files
committedFeb 23, 2017
add: 26.Remove Duplicates from Sorted Array
1 parent 8c67434 commit 5e95964

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is the solution collection of my LeetCode problems, most of them are programmed in JavaScript.
44

5-
Progress: 18/
5+
Progress: 20/
66

77
| ID | Title | Solution | Difficulty |
88
|---| ----- | -------- | ---------- |
@@ -11,6 +11,7 @@ Progress: 18/
1111
|7|[Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [JavaScript](./src/reverse-integer/res.js)|Easy|
1212
|13|[Roman to Integer](https://leetcode.com/problems/roman-to-integer/) | [JavaScript](./src/roman-to-integer/res.js)|Easy|
1313
|22|[Generate Parentheses](https://leetcode.com/problems/generate-parentheses/) | [JavaScript](./src/generate-parentheses/res.js)|Medium|
14+
|26|[Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/) | [JavaScript](./src/remove-duplicates-from-sorted-array/res.js)|Easy|
1415
|66|[Plus One](https://leetcode.com/problems/plus-one/) | [JavaScript](./src/plus-one/res.js)|Easy|
1516
|69|[Sqrt(x)](https://leetcode.com/problems/sqrtx/) | [JavaScript](./src/sqrtx/res.js)|Easy|
1617
|175|[Combine Two Tables](https://leetcode.com/problems/combine-two-tables/)| [SQL](./src/combine-two-tables/res.txt)|Easy|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* res.js
3+
* @authors Joe Jiang (hijiangtao@gmail.com)
4+
* @date 2017-02-23 13:59:15
5+
* @version $Id$
6+
*/
7+
8+
/**
9+
* @param {number[]} nums
10+
* @return {number}
11+
*/
12+
let removeDuplicates = function(nums) {
13+
let arrlen = nums.length,
14+
curInd = 0;
15+
16+
if (arrlen < 2) {
17+
return nums;
18+
}
19+
20+
for (let i=1; i<arrlen; i++) {
21+
if ( nums[curInd] !== nums[i] ) {
22+
curInd++;
23+
nums[curInd] = nums[i];
24+
}
25+
}
26+
27+
return curInd+1;
28+
};

0 commit comments

Comments
 (0)
Please sign in to comment.