unique(未完成)
const unique = arr => {
const sortedArr = arr.sort((a, b) => a > b);
const first = sortedArr[0];
let last = sortedArr[sortedArr.length - 1];
const result = [];
result.push(last);
for(let len = sortedArr.length, i = len - 2; i > 0; i--) {
const temp = sortedArr[i];
if(last === temp) {
continue;
} else {
if(last > temp) {
result.push(temp);
if(first === temp) {
break;
} else {
last = temp;
}
}
}
}
return result;
}
unique(未完成)的更多相关文章
- [占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合
[占位-未完成]scikit-learn一般实例之十一:异构数据源的特征联合 Datasets can often contain components of that require differe ...
- [占位-未完成]scikit-learn一般实例之十:核岭回归和SVR的比较
[占位-未完成]scikit-learn一般实例之十:核岭回归和SVR的比较
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写
A string such as "word" contains the following abbreviations: ["word", "1or ...
- [LeetCode] Count Numbers with Unique Digits 计算各位不相同的数字个数
Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Examp ...
- [LeetCode] Unique Word Abbreviation 独特的单词缩写
An abbreviation of a word follows the form <first letter><number><last letter>. Be ...
- [LeetCode] Unique Binary Search Trees 独一无二的二叉搜索树
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- [LeetCode] Unique Binary Search Trees II 独一无二的二叉搜索树之二
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For e ...
- [LeetCode] Unique Paths II 不同的路径之二
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
随机推荐
- 4-安装mariadb
①yum install mariadb-server mariadb systemctl start mariadb #启动MariaDB systemctl stop mariadb #停止Mar ...
- Sklearn (一) 监督学习
本系列博文是根据SKlearn的一个学习小结,并非原创! 1.直接学习TensorFlow有点不知所措,感觉需要一些基础知识做铺垫. 2.之前机器学习都是理论<Ng机器学习基础>+底层 ...
- dir函数
dir函数: dir() 是一个内置函数,用于列出对象的所有属性及方法 下面进行尝试: 用下面两个tests test2文件做实验 #创建一个类,两个常量,类中函数test1,类中属性, class ...
- Truthy真值
在 JavaScript 中,Truthy (真值)指的是在 布尔值 上下文中转换后的值为真的值.所有值都是真值,除非它们被定义为 falsy (即除了 false,0,"",nu ...
- cdn是否缓存了网站内容,如何查看
查看网站是否缓存,本例以cdnbest的节点程序,浏览器是firefox为例 打开浏览器后按 F12键,再打开网站,如下图显示 HIT就表示有缓存,没有缓存就会显示MISS
- socket failed: EACCES
参考 https://blog.csdn.net/ct_ts/article/details/80010208 <uses-permission android:name=“android.pe ...
- Linux权限赋予远程连接MySQL
1.mysql -u root -p (root)用户名 2.mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'r ...
- FortiGate下视频会议等语音相关配置
关闭老的基于会话的alg机制(即删除session-helper中的SIP条目) config system session-helper delete 13 #删除sip end
- Newtonsoft.Json反序列化(Deserialize)出错:Bad JSON escape sequence
使用Newtonsoft.Json反序列化收到的字串为JObject或其它支持的数据模型,有时错误,提示如下: Bad JSON escape sequence: \c. Path , positio ...
- [leetcode]7. Reverse Integer反转整数
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...