1 Star 0 Fork 0

张志光/Leetcode-js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
26.输出排序数组中的重复项.html 873 Bytes
一键复制 编辑 原始数据 按行查看 历史
zhangzhiguang123 提交于 2019-09-16 19:34 . 力扣
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
/**
* @param {number[]} nums
* @return {number}
*/
var removeDuplicates = function(nums) {
function sortNumber(a,b) //让sort方法以数值大小排序
{
return a - b;
}
let arrNum = nums.sort(sortNumber);
for(let i = 0;i<arrNum.length;i++){
if(arrNum[i]===arrNum[i+1]){
arrNum.splice(i+1,1);
i--; //删除数组元素之后,将下标前移一位,即继续比较下标为i的元素与其后的元素;
}
}
return arrNum.length;
};
alert(removeDuplicates([5,3,2,5,5,5,9,10,11,12]));
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/guangzz/Leetcode-js.git
git@gitee.com:guangzz/Leetcode-js.git
guangzz
Leetcode-js
Leetcode-js
master

搜索帮助