shit LeetCode interview Question

https://leetcode.com/interview/1/

有点晕,啥意思,没太明白,到底是要按什么排序呀?

  1. 去掉 标识符
  2. 不去掉,TMD 也不对呀
  3. 难道。。。
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的更多相关文章

  1. an interview question(1)

    声明:本文为博主原创文章,未经博主允许不得转载. 以下是英文翻译: warnning: Copyright!you can't reprint this blog when you not get b ...

  2. Core Java Interview Question Answer

    This is a new series of sharing core Java interview question and answer on Finance domain and mostly ...

  3. 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 - ...

  4. An interview question from MicroStrategy

    去年校招时的一道面试题,觉得蛮有意思,贴出来. Question: Spy start at a, during an interval he moves |b| to right when b &g ...

  5. an interview question(4)

    版权声明:本文为博主原创文章,未经博主允许不得转载. 写这篇博客前请让博主先吐糟下自己的PC. i3+2G内存+开了一上午=C盘剩下0字节+打开VS2012花了半个小时+一晚上的心情不好 吐槽完PC, ...

  6. an interview question(3)

    最近看了些C面试题顺便复习一下C语言,现贴一些出来和大家分享. #include <stdio.h> void main () { ,,,,};--------- *(ptr++)+=; ...

  7. an interview question(2)

    感觉现在好多面试题还是很注重基础的,今天面试时就遇到这题,回来一查后才知道此题是国内某著名通信公司的一道机试题:) 给定一个数组input[ ],如果数组长度n为奇数,则将数组中最大的元素放到 out ...

  8. Interview Question

    HDS(11.16.2015): How to design an non-stop website like Google or Amazon? What design patterns are y ...

  9. 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 ...

随机推荐

  1. 我为什么不鼓吹 WireGuard

    原文链接:https://fuckcloudnative.io/posts/why-not-wireguard/ 最近有一款新型 VPN 工具备受瞩目,相信很多人已经听说过了,没错就是 WireGua ...

  2. jemeter断言和性能分析

    一.添加断言 1.原因:检查是否有该结果,一般一个请求过去除了400和500的只要通过的都会代表请求成功,比如登录页面及时填写了错误密码,虽然会返回密码错误,但这个请求还是成功的,所以我们要添加断言, ...

  3. 线上一次大量 CLOSE_WAIT 复盘

    https://mp.weixin.qq.com/s/PfM3hEsDa3CMLbbKqis-og 线上一次大量 CLOSE_WAIT 复盘 原创 ms2008 poslua 2019-07-05 最 ...

  4. Python的交互模式和直接运行.py文件有什么区别

    使用文本编辑器 - 廖雪峰的官方网站 https://www.liaoxuefeng.com/wiki/1016959663602400/1017024645952992 直接输入python进入交互 ...

  5. TCMalloc源码学习(二)

    替换libc中的malloc free 不同平台替换方式不同. 基于unix的系统上的glibc,使用了weak alias的方式替换.具体来说是因为这些入口函数都被定义成了weak symbols, ...

  6. python 文件的方法

    1.open() 方法 Python open() 方法用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数,如果该文件无法被打开,会抛出 OSError. 注意:使用 open ...

  7. 在项目中如何自定义的Eslint配置

    一.设置js风格的缩进为4个空格 在你的前端项目中找到.eslintrc.js文件,如图 module.exports = { root: true, parserOptions: { parser: ...

  8. Kafka踩坑填坑记录

    Kafka踩坑填坑记录 一.kafka通过Java客户端,消费者无法接收消息,生产者发送失败消息 二. 一.kafka通过Java客户端,消费者无法接收消息,生产者发送失败消息 在虚拟机上,搭建了3台 ...

  9. Linux-apache httd.conf文件详解

    Linux-apache httd.conf文件详解 # This is the main Apache server configuration file. It contains the # co ...

  10. Java程序操作HDFS

    1.新建项目2.导包 解压hadoop-2.7.3.tar.gzE:\工具\大数据\大数据提升资料\01-软件资料\06-Hadoop\安装包\Java1.8环境下编译\hadoop-2.7.3\ha ...