【leetcode】949. Largest Time for Given Digits
题目如下:
Given an array of 4 digits, return the largest 24 hour time that can be made.
The smallest 24 hour time is 00:00, and the largest is 23:59. Starting from 00:00, a time is larger if more time has elapsed since midnight.
Return the answer as a string of length 5. If no valid time can be made, return an empty string.
Example 1:
Input: [1,2,3,4]
Output: "23:41"Example 2:
Input: [5,5,5,5]
Output: ""Note:
A.length == 40 <= A[i] <= 9
解题思路:就四个数字,把所有组合方式列举一遍,求最大值即可。
代码如下:
class Solution(object):
def largestTimeFromDigits(self, A):
"""
:type A: List[int]
:rtype: str
"""
import itertools
res = -1
for i in itertools.permutations(A,4):
if i[0]*10 + i[1] < 24 and i[2]*10 + i[3] < 60:
res = max(res,(i[0]*1000+i[1]*100+i[2]*10+i[3]))
if res == -1:
return ''
res = str(res).zfill(4)
return res[0:2] + ':' + res[2:]
【leetcode】949. Largest Time for Given Digits的更多相关文章
- 【LeetCode】949. Largest Time for Given Digits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【Leetcode_easy】949. Largest Time for Given Digits
problem 949. Largest Time for Given Digits solution: class Solution { public: string largestTimeFrom ...
- 【LeetCode】764. Largest Plus Sign 解题报告(Python)
[LeetCode]764. Largest Plus Sign 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn ...
- 【LeetCode】813. Largest Sum of Averages 解题报告(Python)
[LeetCode]813. Largest Sum of Averages 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 【Leetcode】179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- 【LeetCode】976. Largest Perimeter Triangle 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 排序 日期 题目地址:https://leetcod ...
- 【LeetCode】952. Largest Component Size by Common Factor 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 并查集 日期 题目地址:https://leetco ...
- 【LeetCode】368. Largest Divisible Subset 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/largest-d ...
- 【LeetCode】84. Largest Rectangle in Histogram 柱状图中最大的矩形(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调栈 日期 题目地址: https://leetc ...
随机推荐
- SP2-0618: Cannot find the Session Identifier.
[oracle@trade1 ~]$ sqlplus user1/user1 SQL*Plus: Release 11.2.0.3.0 Production on Tue Aug 6 14:31:1 ...
- C++在windows平台下不存在strptime函数,可以绕过该函数
https://blog.csdn.net/u011077672/article/details/50524469?utm_source=blogxgwz1
- 【leetcode】924.Minimize Malware Spread
题目如下: In a network of nodes, each node i is directly connected to another node j if and only if grap ...
- BZOJ 3105: [cqoi2013]新Nim游戏(线性基)
解题思路 \(nim\)游戏先手必胜的条件是异或和不为\(0\),也就是说第一个人拿走了若干堆后不管第二个人怎么拿都不能将剩余堆的异或和变成\(0\).考虑线性基,其实就是每个数对线性基都有贡献,任何 ...
- CJE-Jenkins认证工程师考试预约报名流程
先决条件 考试费用150美元,需要由master/visr信用卡支付 考试全英文 哈哈哈 考试目的 通过各种渠道能够找到Jenkins的学习资料,并能够完成jenkins的配置管理,还是想全面的系统 ...
- 遵循PEP8风格指南
整理来自 effective python 一 空白 1 使用space来标识缩进,而不是tab 2 和语法相关的每层缩进都使用4个空格 3 每行的字符数不应该超过79 4 对于多行的表达式,除了首行 ...
- Rust <8>:lifetime 高级语法与 trait 关联绑定
一.生命周期关联:如下声明表示,'s >= 'c struct Parser<'c, 's: 'c> { context: &'c Context<'s>, } ...
- 搭建RAID10(5块硬盘)过程并模拟其中一块硬盘损坏
首先:RAID 10,实际是将RAID 0和RAID 1标准结合的产物,在连续地以位或字节为单位分割数据并且并行读/写多个磁盘的同时,为每一块磁盘作磁盘镜像进行冗余.它的优点是同时拥有RAID 0的超 ...
- python之正则表达式【re】
在处理字符串时,经常会有查找符合某些规则的字符串的需求.正则表达式就是用于藐视这些规则的工具.换句话说,正则表达式是记录文本规则的代码. 1.行定位符. 行定位符就是用来表示字符串的边界,“^”表示开 ...
- 转 Python - openpyxl 读写操作Excel
Python - openpyxl 读写操作Excel openpyxl特点 openpyxl(可读写excel表)专门处理Excel2007及以上版本产生的xlsx文件,xls和xlsx之间 ...