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:

  1. A.length == 4
  2. 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;
    ;
}

最新文章

  1. Ubuntu杂记——Ubuntu自带拼音输入发杂乱不堪
  2. Linux nohup 程序后台运行
  3. imp导入oracle的dmp备份数据
  4. Debian GNU/kFreeBSD是什么
  5. [CareerCup] 12.3 Test Move Method in a Chess Game 测试象棋游戏中的移动方法
  6. 转:Scrapy安装、爬虫入门教程、爬虫实例(豆瓣电影爬虫)
  7. Java类的初始化过程及清理
  8. 沈逸老师PHP魔鬼特训笔记(2)
  9. 关于Marsedit和我的163博客
  10. 04737_C++程序设计_第5章_特殊函数和成员
  11. 轻松学会ES6新特性之生成器
  12. JSON--stringify() 和 parse() 方法
  13. Twisted 延迟调用
  14. [Python学习之路] 猜大小游戏
  15. SSIS - 7.发邮件任务
  16. HDU 6304 Chiaki Sequence Revisited
  17. 【centos】 error: command &#39;gcc&#39; failed with exit status 1
  18. win7防火墙端口开放
  19. 并发和多线程-说说面试长提平时少用的volatile
  20. c++11支持类数据成员的初始化

热门文章

  1. MySQL的GTID复制
  2. SNMP Introduction
  3. 【建项目】eclipse maven建立多模块工程
  4. pybedtools --bedtools的python包
  5. JavaScript里Math对象的ceil()、floor()、round()方法的区别
  6. Singleton(单例)
  7. SQL Server 跨服务器 不同数据库之间复制表的数据
  8. bzoj 3730 震波 (动态点分治)
  9. Ubuntu上识别不到安卓设备或者显示出“????”,提示No Permission
  10. 浅谈jsonp