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 ...
随机推荐
- STP 根桥、根端口、指定端口是如何选举的
学习HCIA过程中,对交换机的根桥.跟端口以及指定端口选举有些迷糊,也度娘了一番,总觉得一部分人解释的不够全面精细.通过仔细研究最终有了自己的理解,分享给大家,如果纰漏,欢迎指正. STP收敛过程: ...
- 浅析Linux用户空间中的Mmap
一.MMap基础概念 mmap是一种内存映射文件的方法,即将一个文件或者其它对象映射到进程的地址空间,实现文件磁盘地址和进程虚拟地址空间中一段虚拟地址的一一对映关系.实现这样的映射关系后,进程就可以采 ...
- code-server scala error: object apache is not a member of package org
原因是scala缺少包,需要把spark或对应的包放入scala目录下的lib,然后重启主机,在terminal输入reboot即可. 如果不重启主机,则在交互式编程中可以成功import.但是直接在 ...
- The Garbage Collection Handbook
The Garbage Collection Handbook The Garbage Collection Handbook http://gchandbook.org/editions.html ...
- git branch --set-upstream-to=
test@uat:/usr/server/app_server# git config --local -lcore.repositoryformatversion=0core.filemode=tr ...
- Index-Only Scans and Covering Indexes
小结: 1.覆盖索引 回表 2. All indexes in PostgreSQL are secondary indexes, meaning that each index is stored ...
- .Vue-router跳转和location.href有什么区别
使用location.href='/url'来跳转,简单方便,但是刷新了页面:使用history.pushState('/url'),无刷新页面,静态跳转:引进router,然后使用router.pu ...
- 洛谷P3413 P6754
双倍经验题 由于我先做的 P6754,所以一切思路基于 P6754 的题目 " P6754 这题就是 P3413 的究极弱化版 " --By Aliemo. P6754 Descr ...
- Nginx上安装SSL证书
准备 参考 :链接 下载的Nginx证书压缩文件解压后包含: .pem:证书文件.PEM文件的扩展名为CRT格式. .key:证书密钥文件.申请证书时如果未选择自动创建CRS,则下载的证书文件压缩包中 ...
- csv的读写操作
cvs简介: CSV 全称 Comma-Separated Values,中文叫逗号分隔值或字符分隔值,它以纯文本形式存储表格数据(数字和文本),其本质就是一个字符序列,可以由任意数目的记录组成,记录 ...