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. (转载)微软数据挖掘算法:Microsoft Naive Bayes 算法(3)

    介绍: Microsoft Naive Bayes 算法是一种基于贝叶斯定理的分类算法,可用于探索性和预测性建模. Naïve Bayes 名称中的 Naïve 一词派生自这样一个事实:该算法使用贝叶 ...

  2. redis6.0多线程

    https://www.sohu.com/a/331991216_268033 执行还是单线程     读写解析多线程   6.0 https://segmentfault.com/a/1190000 ...

  3. 《进击吧!Blazor!》第一章 3.页面制作

    作者介绍 陈超超Ant Design Blazor 项目贡献者拥有十多年从业经验,长期基于.Net技术栈进行架构与开发产品的工作,Ant Design Blazor 项目贡献者,现就职于正泰集团 写专 ...

  4. Jsp数字格式化

    日期格式(2008年5月5日22点00分23秒) <fmt:formatDate value="<%=new Date() %>" pattern="y ...

  5. 前端api管理工具YApi

    使用YApi接口管理工具,提升前端开发效率前端开发苦恼: 代码中使用json数据模拟后端api数据,注释调取api接口代码,代码乱七八糟 为了测试不同case,央求后端人员返回不同的数据,返回状态.返 ...

  6. 如何使用Conda源快速安装PyTorch?

    数据科学交流群,群号:189158789,欢迎各位对数据科学感兴趣的小伙伴的加入! 1.切换国内源 1.1.在家目录生成.condarc conda config --set show_channel ...

  7. Linux 输入输出重定向, &>file, 2>&1, 1>&2

    Linux 输入输出重定向, &>file, 2>&1, 1>&2 一.1和2在Linux中代表什么 1.1 输出重定向 1.2 输入重定向 1.3 绑定重定 ...

  8. 4. Linux工作目录切换和文本文件编辑命令

    1.pwd:显示用户当前所处的工作目录 举例:[root@Centos ~]# pwd /root 2.cd:切换工作路径   "cd -"命令返回到上一次所处的目录 " ...

  9. Flink-v1.12官方网站翻译-P006-Intro to the DataStream API

    DataStream API介绍 本次培训的重点是广泛地介绍DataStream API,使你能够开始编写流媒体应用程序. 哪些数据可以流化? Flink的DataStream APIs for Ja ...

  10. JVM之堆参数

    1.Java 7和Java 8区别 Java 7堆结构 JDK 1.8之后将最初的永久代取消了,由元空间取代. 在Java8中,永久代已经被移除,被一个称为元空间的区域所取代.元空间的本质和永久代类似 ...