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 ...
随机推荐
- bitbucket 上公钥SSH key如何add key并进行项目运用
前提:从sourcetree 添加项目时老是拉取不下来,查到原因是应为bitbucket需要SSH key公钥 目的:公钥相当于你在任何一台电脑只要有公钥授权就可以随时提交代码到服务器 原因: 1.很 ...
- 说下spring生命周期
面试官:说下spring生命周期 程序员:不会 那你先回去等消息吧 Bean实现了BeanNameAware,Spring会将Bean的ID透传给setBeanName java.后端开发.程 ...
- web服务器案例
HTTP 请求方式 GET 获取数据 POST 修改数据 PUT 保存数据 DELETE 删除 OPTI ...
- ROS--导航、路径规划和SLAM
一.用move_base导航走正方形 1. roscore 2.执行 roslaunch rbx1_bringup fake_turtlebot.launch 然后 roslaunch rbx1_na ...
- py库: arrow (时间)
arrow是个时间日期库,简洁易用.支持python3.6 https://arrow.readthedocs.io/en/latest/ arrow官网api https://github.com/ ...
- grep -A -B -C 显示抓取的前后几行参数
我经常用grep找东西,比如用户名和密码.大部分站点和用户名和密码都是在一样的,方便grep查找.有时,为了文本好看,我会放在多行.比如 wikipedia多个语言版本上有多个账号,就放在wikipe ...
- leetcode124
class Solution { int maxValue; public int maxPathSum(TreeNode root) { maxValue = Integer.MIN_VALUE; ...
- 阿里云视频直播PHP-SDK
阿里云 视频直播 配置 及 PHP-SDK 接入教程准备工作域名管理配置鉴权地址生成器及DEMO演示-熟悉鉴权接入SDK推流回调的配置阿里云 视频直播 配置 及 PHP-SDK 接入教程 个人感觉,阿 ...
- mysql const与eq_ref的区别
简单地说是const是直接按主键或唯一键读取,eq_ref用于联表查询的情况,按联表的主键或唯一键联合查询. 下面的内容翻译自官方方档: const该表最多有一个匹配行, 在查询开始时读取.由于只有一 ...
- lastIndexOf() 找出指定元素出现的所有位置(返回的是下标数组)---lastIndexOf() 这个方法是倒叙查找,正序的是indexOf()
var indices = []; var array = ['a', 'b', 'a', 'c', 'a', 'd']; var element = 'a'; var idx = array.las ...