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. 前端工程构建之谈:gulp3要不要升级到Gulp4

    关于升级还是不升级,这是一个哲学问题. gulp4的语法更加现代,支持ES6的大部分写法,使用exports的方式去暴露任务组合,更加灵活和便捷. gulp4同时也提供了很多强大的API,例如para ...

  2. html新特性笔记

    HTML5知识总结 l  文档类型声明:<!DOCTYPE HTML> l  新绘制元素: Canvas:标签定义图形,比如图表和其他图像.该标签基于 JavaScript 的绘图 API ...

  3. Hash Join: Basic Steps

    Joins https://docs.oracle.com/database/121/TGSQL/tgsql_join.htm#TGSQL242 tidb/index_lookup_hash_join ...

  4. Linux的.a、.so和.o文件 windows下obj,lib,dll,exe的关系 动态库内存管理 动态链接库搜索顺序 符号解析和绑定 strlen函数的汇编实现分析

    Linux的.a..so和.o文件 - chlele0105的专栏 - CSDN博客 https://blog.csdn.net/chlele0105/article/details/23691147 ...

  5. Elasticsearch从0到千万级数据查询实践(非转载)

    1.es简介 1.1 起源 https://www.elastic.co/cn/what-is/elasticsearch,es的起源,是因为程序员Shay Banon在使用Apache Lucene ...

  6. 从一片森林(JavaScript)到另一片森林(C++)

    从JavaScript到C Plus Plus 作为一个忠诚的Web开发者,JavaScript几乎是我这一年多以来的首选,不管是开发网站后端服务,还是开发跨端应用,我都会首选一个使用JavaScri ...

  7. HTML5 使用浏览器内置数据库之 indexedDB

    indexedDB是H5规范里的浏览器内置数据库,是nosql数据库的一种.因为另一种数据库Web SQL不再受W3C支持,所以还得学习下这个. 基本情况 兼容性:ie11及以上都支持, W3C是这么 ...

  8. c#的dllimport使用方法详解(Port API)

    DllImport是System.Runtime.InteropServices命名空间下的一个属性类,其功能是提供从非托管DLL(托管/非托管是微软的.net framework中特有的概念,其中, ...

  9. P3355 骑士共存问题 (最小割)

    题意:nxn的棋盘 有m个坏点 求能在棋盘上放多少个马不会互相攻击 题解:这个题仔细想想居然和方格取数是一样的!!! 每个马他能攻击到的地方的坐标 (x+y)奇偶性不一样 于是就黑白染色 s-> ...

  10. Codeforces Round #648 (Div. 2) D. Solve The Maze

    这题犯了一个很严重的错误,bfs 应该在入队操作的同时标记访问,而不是每次只标记取出的队首元素. 题目链接:https://codeforces.com/contest/1365/problem/D ...