File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
src/remove-duplicates-from-sorted-array Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
This is the solution collection of my LeetCode problems, most of them are programmed in JavaScript.
4
4
5
- Progress: 18 /
5
+ Progress: 20 /
6
6
7
7
| ID | Title | Solution | Difficulty |
8
8
| ---| ----- | -------- | ---------- |
@@ -11,6 +11,7 @@ Progress: 18/
11
11
| 7| [ Reverse Integer] ( https://leetcode.com/problems/reverse-integer/ ) | [ JavaScript] ( ./src/reverse-integer/res.js ) | Easy|
12
12
| 13| [ Roman to Integer] ( https://leetcode.com/problems/roman-to-integer/ ) | [ JavaScript] ( ./src/roman-to-integer/res.js ) | Easy|
13
13
| 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|
14
15
| 66| [ Plus One] ( https://leetcode.com/problems/plus-one/ ) | [ JavaScript] ( ./src/plus-one/res.js ) | Easy|
15
16
| 69| [ Sqrt(x)] ( https://leetcode.com/problems/sqrtx/ ) | [ JavaScript] ( ./src/sqrtx/res.js ) | Easy|
16
17
| 175| [ Combine Two Tables] ( https://leetcode.com/problems/combine-two-tables/ ) | [ SQL] ( ./src/combine-two-tables/res.txt ) | Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments