Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 594ef31

Browse files
committed
去掉数组中的重复项,不使用其他空间
1 parent bd78fab commit 594ef31

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var removeDuplicates = function(nums) {
6+
var copyNums = nums;
7+
for (var i=0; i<copyNums.length; i++) {
8+
for (var j=i+1; j<copyNums.length;) {
9+
if (copyNums[i] === copyNums[j]) {
10+
copyNums.splice(j, 1);
11+
continue;
12+
}
13+
j++;
14+
}
15+
}
16+
return copyNums;
17+
};

0 commit comments

Comments
 (0)