949. Largest Time for Given Digits
2024-09-11 23:03:01
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; ; }
最新文章
- Ubuntu杂记——Ubuntu自带拼音输入发杂乱不堪
- Linux nohup 程序后台运行
- imp导入oracle的dmp备份数据
- Debian GNU/kFreeBSD是什么
- [CareerCup] 12.3 Test Move Method in a Chess Game 测试象棋游戏中的移动方法
- 转:Scrapy安装、爬虫入门教程、爬虫实例(豆瓣电影爬虫)
- Java类的初始化过程及清理
- 沈逸老师PHP魔鬼特训笔记(2)
- 关于Marsedit和我的163博客
- 04737_C++程序设计_第5章_特殊函数和成员
- 轻松学会ES6新特性之生成器
- JSON--stringify() 和 parse() 方法
- Twisted 延迟调用
- [Python学习之路] 猜大小游戏
- SSIS - 7.发邮件任务
- HDU 6304 Chiaki Sequence Revisited
- 【centos】 error: command &#39;gcc&#39; failed with exit status 1
- win7防火墙端口开放
- 并发和多线程-说说面试长提平时少用的volatile
- c++11支持类数据成员的初始化
热门文章
- MySQL的GTID复制
- SNMP Introduction
- 【建项目】eclipse maven建立多模块工程
- pybedtools --bedtools的python包
- JavaScript里Math对象的ceil()、floor()、round()方法的区别
- Singleton(单例)
- SQL Server 跨服务器 不同数据库之间复制表的数据
- bzoj 3730 震波 (动态点分治)
- Ubuntu上识别不到安卓设备或者显示出“????”,提示No Permission
- 浅谈jsonp