【leetcode】937. Reorder Log Files
题目如下:
You have an array of
logs
. Each log is a space delimited string of words.For each log, the first word in each log is an alphanumeric identifier. Then, either:
- Each word after the identifier will consist only of lowercase letters, or;
- Each word after the identifier will consist only of digits.
We will call these two varieties of logs letter-logs and digit-logs. It is guaranteed that each log has at least one word after its identifier.
Reorder the logs so that all of the letter-logs come before any digit-log. The letter-logs are ordered lexicographically ignoring identifier, with the identifier used in case of ties. The digit-logs should be put in their original order.
Return the final order of the logs.
Example 1:
Input: ["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"]
Output: ["g1 act car","a8 act zoo","ab1 off key dog","a1 9 2 3 1","zo4 4 7"]Note:
0 <= logs.length <= 100
3 <= logs[i].length <= 100
logs[i]
is guaranteed to have an identifier, and a word after the identifier.
解题思路:题目实在太简单了,我的方法是创建两个数组letter和digit,接下来遍历logs,如果logs[i]的最后一个字符是数字,存入digit;否则,存入letter。遍历完成后,对letter进行排序,最后返回letter + digit。
随便说说:最近真的是太忙了,基本没有时间做题。
代码如下:
class Solution(object):
def reorderLogFiles(self, logs):
"""
:type logs: List[str]
:rtype: List[str]
"""
letter = []
digit = []
for i in logs:
if i[-1].isdigit():
digit.append(i)
else:
letter.append(i)
def cmpf(v1,v2):
lv1 = v1.split(' ')
lv2 = v2.split(' ')
for i in range(1,min(len(lv1),len(lv2))):
if lv1[i] == lv2[i]:
continue
return cmp(lv1[i],lv2[i])
return len(lv1) - len(lv2) letter.sort(cmp = cmpf)
return letter + digit
【leetcode】937. Reorder Log Files的更多相关文章
- 【LeetCode】937. Reorder Log Files 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 分割和排序 日期 题目地址:https://leet ...
- 【Leetcode_easy】937. Reorder Log Files
problem 937. Reorder Log Files solution: class Solution { public: vector<string> reorderLogFil ...
- 【LeetCode】143. Reorder List 解题报告(Python)
[LeetCode]143. Reorder List 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://f ...
- LeetCode 937 Reorder Log Files 解题报告
题目要求 You have an array of logs. Each log is a space delimited string of words. For each log, the fi ...
- 937. Reorder Log Files
You have an array of logs. Each log is a space delimited string of words. For each log, the first w ...
- leecode 937 Reorder Log Files (模拟)
传送门:点我 You have an array of logs. Each log is a space delimited string of words. For each log, the ...
- 【Leetcode】143. Reorder List
Question: Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You ...
- 【LeetCode】436. Find Right Interval 解题报告(Python)
[LeetCode]436. Find Right Interval 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...
- 【LeetCode】692. Top K Frequent Words 解题报告(Python)
[LeetCode]692. Top K Frequent Words 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/top ...
随机推荐
- Oracle RAC常用命令
Oracle Clusterware的命令集可以分为以下4种,其中用的最多的是crsctl和srvctl:节点层:osnodes olsnodes -n -i -s olsnodes -l -p 网络 ...
- java生成快递单并调用打印机打印
生成快递单过程中需要生成条形码,生成条形码可参考:https://www.cnblogs.com/linbky/p/12091248.html 下面这段代码生成的快递单是完全符合京东快递的10 x 1 ...
- C/C++ C++ 11 std::function和std::bind用法
std::bind() std::bind 主要用于绑定生成目标函数,一般用于生成的回调函数,cocos的回退函数都是通过std::bind和std::function实现的.两个点要明白: 1.绑定 ...
- DataInput接口说明及其实现类
一. DataInput接口 DataInput接口提供了一系列的方法从二进制流中读取字节,并将读取出来的字节转换成任意的java基本类型,包括转换成UTF-8类型的字符串. 该接口中主要方法介绍如下 ...
- 如何在MaxCompute上处理存储在OSS上的开源格式数据
0. 前言 MaxCompute作为使用最广泛的大数据平台,内部存储的数据以EB量级计算.巨大的数据存储量以及大规模计算下高性能数据读写的需求,对于MaxCompute提出了各种高要求及挑战.处在大数 ...
- 【Vue】新版vue解决跨域问题
vue.config.js module.exports = { devServer: { proxy: { "/api": { target: "http://192. ...
- delphi 异形窗体可半透明
unit xDrawForm; interface uses Windows, Messages, SysUtils, Classes, Controls, Forms, Menus, Graphic ...
- (转)使用InfluxDB+cAdvisor+Grafana配置Docker监控
文档来源 文档来源:How to setup Docker Monitoring 由garyond翻译.校正及整理 Docker监控简介 我们提供的Docker主机和容器越来越多,对Docker服务器 ...
- 专家揭秘:STM32启动过程全解
电子发烧友网核心提示:本文主要阐述了STM32启动过程全面解析,包括启动过程的介绍.启动代码的陈列以及深入解析. 相对于ARM上一代的主流ARM7/ARM9内核架构,新一代Cortex内核架构的启动方 ...
- English-Difference between original and source
最近跟网页翻译怼上了,在给翻译前的页面起名是纠结于使用 original page 还是 source page,就查了一下 original 和 source 的区别. original: n. 原 ...