shit LeetCode interview Question
shit LeetCode interview Question
https://leetcode.com/interview/1/

有点晕,啥意思,没太明白,到底是要按什么排序呀?
- 去掉 标识符
- 不去掉,TMD 也不对呀
- 难道。。。
const uniqueKey = arr.slice(1).join(` `).replace(/[0-9]/g, ``);
// const uniqueKey = arr.join(` `).replace(/[0-9]/g, ``);

/**
* @param {string[]} logs
* @return {string[]}
*/
var reorderLogFiles = function(logs) {
let result = [];
let nums = [];
let strs = [];
// let map = new Map();
let obj = {};
for(let item of logs) {
const arr = item.split(` `);
if(!/[A-Za-z]/g.test(arr[1])) {
// num
nums.push(item);
} else {
// str
// strs.push(item);
// log(`arr.slice(1).join(' ') `, arr.slice(1).join(` `))
// map.set(arr.slice(1).join(` `), item);
// if(!obj[arr.join(` `)]) {
// obj[arr.join(` `)] = item;
// } else {
// obj[arr.join(` `) + Date.now()] = item;
// }
const uniqueKey = arr.slice(1).join(` `).replace(/[0-9]/g, ``);
// const uniqueKey = arr.join(` `).replace(/[0-9]/g, ``);
if(!obj[uniqueKey]) {
obj[uniqueKey] = item;
} else {
obj[uniqueKey + `` + Date.now()] = item;
}
// if(!map.has(arr[1])) {
// map.set(arr[1], item);
// } else {
// map.set(arr[1] + 1, item);
// }
}
}
// strs.sort();
for(let key of Object.keys(obj).sort()) {
// log(`key`, key, obj[key])
strs.push(obj[key]);
}
// for(let item of map.sort()) {
// log(`item`, item)
// strs.push(item[1]);
// }
result = strs.concat(nums);
return result;
};
// var reorderLogFiles = function(logs) {
// let result = [];
// let nums = [];
// let strs = [];
// let map = new Map();
// for(let log of logs) {
// const arr = log.split(` `);
// if(!/[A-Za-z]/g.test(arr[1])) {
// // num
// nums.push(log);
// } else {
// // str
// // strs.push(log);
// map.set(arr.slice(1).join(` `), log);
// // if(!map.has(arr[1])) {
// // map.set(arr[1], log);
// // } else {
// // map.set(arr[1] + 1, log);
// // }
// }
// }
// // strs.sort();
// for(let log of map) {
// strs.push(log[1]);
// }
// result = strs.concat(nums);
// return result;
// };
refs
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
shit LeetCode interview Question的更多相关文章
- an interview question(1)
声明:本文为博主原创文章,未经博主允许不得转载. 以下是英文翻译: warnning: Copyright!you can't reprint this blog when you not get b ...
- Core Java Interview Question Answer
This is a new series of sharing core Java interview question and answer on Finance domain and mostly ...
- JavaScript interview Question - Create a Array with two papameters without using loop!
JavaScript interview Question - Create a Array with two papameters without using loop! JavaScript - ...
- An interview question from MicroStrategy
去年校招时的一道面试题,觉得蛮有意思,贴出来. Question: Spy start at a, during an interval he moves |b| to right when b &g ...
- an interview question(4)
版权声明:本文为博主原创文章,未经博主允许不得转载. 写这篇博客前请让博主先吐糟下自己的PC. i3+2G内存+开了一上午=C盘剩下0字节+打开VS2012花了半个小时+一晚上的心情不好 吐槽完PC, ...
- an interview question(3)
最近看了些C面试题顺便复习一下C语言,现贴一些出来和大家分享. #include <stdio.h> void main () { ,,,,};--------- *(ptr++)+=; ...
- an interview question(2)
感觉现在好多面试题还是很注重基础的,今天面试时就遇到这题,回来一查后才知道此题是国内某著名通信公司的一道机试题:) 给定一个数组input[ ],如果数组长度n为奇数,则将数组中最大的元素放到 out ...
- Interview Question
HDS(11.16.2015): How to design an non-stop website like Google or Amazon? What design patterns are y ...
- Amazon Interview Question: Design an OO parking lot
Design an OO parking lot. What classes and functions will it have. It should say, full, empty and al ...
随机推荐
- SpringIOC的注解应用
SpringIOC的注解应用 在之前的项目中,我们都是通过xml文件进行bean或者某些属性的赋值,其实还有另外一种注解的方式,在企业开发中使用的很多,在bean上添加注解,可以快速的将bean注 ...
- 获取控制台的错误信息 onerror
js 获取控制台的错误信息 https://www.bbsmax.com/A/Vx5ML2NmJN/ <!DOCTYPE html> <html lang="en" ...
- session和cookie自动登录机制
cookie的存储 cookie是浏览器支持的一种本地存储方式.以dict,键值对方式存储. {"sessionkey": "123"} 浏览器会自动对于它进行 ...
- tcp服务器
如同上面的电话机过程一样,在程序中,如果想要完成一个tcp服务器的功能,需要的流程如下: socket创建一个套接字 bind绑定ip和port listen使套接字变为可以被动链接 accept等待 ...
- python3中zip对象的使用
zip(*iterables) zip可以将多个可迭代对象组合成一个迭代器对象,通过迭代取值,可以得到n个长度为m的元组.其中n为长度最短可迭代对象的元素个数,m为可迭代对象的个数.并且每个元组的第i ...
- jQuery——开发插件
当我们编写的代码可以供其他人甚至我们自己重用的时候,可以通过将这些代码打包成一个新插件. ###**在插件中使用别名∗∗自定义的插件就应该始终都使用jQuery这个名字来调用jQuery方法,或者也可 ...
- Docker容器内Mysql大小写敏感方案解决
Docker容器内Mysql大小写敏感方案解决 一.(lower_case_table_names)参数说明 二.Docker 部署 MySql 并修改为大小写不敏感 2.1直接在Docker启动的时 ...
- Gitlab + DRBD HA
部署简介: 为了gitlab有容灾的能力,所以部署一个HA的小集群,用到的软件有 gitlab 和brbd,目前现有环境为 master节点 系统版本:CentOS release 6.5 (Fina ...
- MySQL数据库---配置文件及数据文件
1.主配置文件 #/usr/local/mysql/bin/mysqld --verbose --help |grep -A 1 'Default options' #cat /etc/my.cnf ...
- linux基础进阶命令详解(输出重定向(2>&1,1>&2,&>file)、输入重定向、管道符、通配符、三种引号、软连接、硬链接、根“/”、绝对路径vs相对路径)
本章命令(共9个): 1 2 3 4 5 6 7 8 9 输出重定向 输入重定向 管道符 通配符 三种引号 软连接 硬链接 根"/" 绝对路径vs相对路径 1.输出重定向 作用:一 ...