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: [,,,]
- Output: "23:41"
Example 2:
- Input: [,,,]
- Output: ""
Note:
A.length == 4
0 <= A[i] <= 9
过滤掉不匹配的时间,然后更新最大时间即可。
- #include <iostream>
- #include <algorithm>
- #include <vector>
- using namespace std;
- class Solution
- {
- public:
- string largestTimeFromDigits(vector<int>& a)
- {
- vector<,-);
- sort(a.begin(),a.end());
- do
- {
- ]>)
- continue;
- ]*+a[]>=)
- continue;
- ]*+a[]>=)
- continue;
- ]>b[]||a[]>b[]||a[]>b[]||a[]>b[])
- ;i<;++i)
- b[i]=a[i];
- }while(next_permutation(a.begin(),a.end()));
- ]==-)
- return "";
- ])+to_string(b[])+])+to_string(b[]);
- }
- };
- int main()
- {
- Solution s;
- ]={,,,};
- vector<);
- cout<<s.largestTimeFromDigits(t)<<endl;
- ;
- }
949. Largest Time for Given Digits的更多相关文章
- 【Leetcode_easy】949. Largest Time for Given Digits
problem 949. Largest Time for Given Digits solution: class Solution { public: string largestTimeFrom ...
- 【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 ...
- 【LeetCode】949. Largest Time for Given Digits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- [Swift]LeetCode949. 给定数字能组成的最大时间 | 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 t ...
- 113th LeetCode Weekly Contest 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 t ...
- LeetCode.949-给定数字的最大时间(Largest Time for Given Digits)
这是悦乐书的第363次更新,第391篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第225题(顺位题号是949).给定4个整数组成的数组,返回最大的24小时时间. 最小的 ...
- Leetcode949. Largest Time for Given Digits给定数字能组成最大的时间
给定一个由 4 位数字组成的数组,返回可以设置的符合 24 小时制的最大时间. 最小的 24 小时制时间是 00:00,而最大的是 23:59.从 00:00 (午夜)开始算起,过得越久,时间越大. ...
- Weekly Contest 113
949. Largest Time for Given Digits (string::compare) Given an array of 4 digits, return the largest ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
随机推荐
- Qt的信号和槽是如何工作的
用Qt做过开发的朋友,不知道是否曾为下面这些问题疑惑过:我们知道Qt是基于C++的,Qt写的代码最终还是要由C++编译器来编译,但是我们的Qt代码中有很多C++里没有的关键字,比如slots\sign ...
- linux_一些shell命令分析记录
一.用于shell脚本的界面命令交互 echo "请输入css-dist下载地址:" read addcss echo "开始下载css的zip包"( wget ...
- 20145339顿珠达杰 《网络对抗技术》 逆向与Bof基础
目的 通过一些方法,使能够运行本不该被运行的代码部分,或得到shell的使用: 将正常运行代码部分某处call后的目标地址,修改为另一部分我们希望执行.却本不应该执行的代码部分首地址(这需要我们有一定 ...
- 如何在命令提示符下编译运行含有Package的java文件
这篇是大二自学Java的时候记下的笔记,中午回顾印象笔记的时候意外看到了这篇.看到多年前写下的文字,我想起那时候我对Java的懵懵懂懂,每天晚上在图书馆照着书写书上的示例代码,为一个中文分号绞尽脑汁, ...
- 【javascript】数据结构-队列
<!DOCTYPE html> <html> <head> <title>queue</title> <meta charset=&q ...
- 导入tensorflow:ImportError: libcublas.so.9.0: cannot open shared object file: No such file or director【转】
本文转载自:https://blog.csdn.net/ksws0292756/article/details/80034086 版权声明:本文为博主原创文章,转载请一定附上博主原文链接,并署名转自Z ...
- 【熊猫TV】《程序员》:聚光灯下的熊猫TV技术架构演进
2015年开始的百播大战,熊猫TV是其中比较特别的一员. 说熊猫TV是含着金钥匙出生的公子哥不为过.还未上线,就频频曝光,科技号,微博稿,站上风口浪尖.内测期间更是有不少淘宝店高价倒卖邀请码,光内测时 ...
- HDU 1565 方格取数(1)(最大点权独立集)
http://acm.hdu.edu.cn/showproblem.php?pid=1565 题意: 给你一个n*n的格子的棋盘,每个格子里面有一个非负数. 从中取出若干个数,使得任意的两个数所在的格 ...
- IIS 7.5 配置 php 5.4.22 链接 sql 2008(用PDO链接数据库)
最近在接触PHP这块,关于在wndows系统下的php配置,虽然网上已经很多文章,但有时候有些配置找起也麻烦,所以分享给大家. 一.php 5.4.22 下载地址 http://windows.php ...
- nohup 不生成 nohup.out的方法
nohup java -jar /xxx/xxx/xxx.jar >/dev/>& & 关键在于最后的 >/dev/>& 部分,/dev/null是一个 ...