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;
    ;
}

949. Largest Time for Given Digits的更多相关文章

  1. 【Leetcode_easy】949. Largest Time for Given Digits

    problem 949. Largest Time for Given Digits solution: class Solution { public: string largestTimeFrom ...

  2. 【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 ...

  3. 【LeetCode】949. Largest Time for Given Digits 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  4. [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 ...

  5. 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 ...

  6. LeetCode.949-给定数字的最大时间(Largest Time for Given Digits)

    这是悦乐书的第363次更新,第391篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第225题(顺位题号是949).给定4个整数组成的数组,返回最大的24小时时间. 最小的 ...

  7. Leetcode949. Largest Time for Given Digits给定数字能组成最大的时间

    给定一个由 4 位数字组成的数组,返回可以设置的符合 24 小时制的最大时间. 最小的 24 小时制时间是 00:00,而最大的是 23:59.从 00:00 (午夜)开始算起,过得越久,时间越大. ...

  8. Weekly Contest 113

    949. Largest Time for Given Digits (string::compare) Given an array of 4 digits, return the largest ...

  9. Swift LeetCode 目录 | Catalog

    请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift    说明:题目中含有$符号则为付费题目. 如 ...

随机推荐

  1. url的正则表达式

    http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?  

  2. 微信 audio 获取 duration 为 NaN 的解决方法

    先加load() myaudio.load(); myaudio.oncanplay = function () { alert(myaudio.duration); } load() 方法用于在更改 ...

  3. 337BRoutine Problem

    /*给出你图片的长和宽的比例a:b 和摄像头的比例c:d,然后叫你求最后将图片放进摄像头 以后,剩余的面积比上摄像头的总面积,注意要化简为最简形式,而且摄像头要设置成至少一条边和图片相等 做法:先将两 ...

  4. # 20145106 《Java程序设计》第3周学习总结

    教材学习内容总结 在本周的学习中,我看到了这样一句话:"使用java撰写程序几乎都是在使用对象(object),要产生对象必须先定义类(class),类是对象的设计图,对象是类的实例(ins ...

  5. 20145328 《网络对抗技术》逆向及Bof基础实践

    20145328 <网络对抗技术>逆向及Bof基础实践 实践内容 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回 ...

  6. BootStrap iCheck插件全选与获取value值的解决方法

    这篇文章主要介绍了BootStrap iCheck插件全选与获取value值的解决方法,解决方法其实很简单,下面小编给大家分享下这方面的知识 在使用jQuery iCheck 插件的时候遇到了一个问题 ...

  7. 2017NOIP模拟赛-科普基地

    今天回来打的第一场NOIP难度的试题,结果惨不忍睹.写一下每道题的做法,然后每道题犯的__弱智__错误 UPD:2018.9.15 突然这篇题解就变成很多大佬要看的了,因为之前是写给自己看的,所以写的 ...

  8. 在 php 中使用 strace、gdb、tcpdump 调试工具

    转自:http://www.syyong.com/php/Using-strace-GDB-and-tcpdump-debugging-tools-in-PHP.html 在 php 中我们最常使用调 ...

  9. 递归--练习8--noi1788Pell数列

    递归--练习8--noi1788Pell数列 一.心得 5 1. 6 //直接递归Time Limit Exceeded 7 //那就记忆化递归 8 2. 9 直接记忆化递归后还有问题 10 a[k] ...

  10. Android 之低版本高版本实现沉浸式状态栏

    沉浸式状态栏确切的说应该叫做透明状态栏.一般情况下,状态栏的底色都为黑色,而沉浸式状态栏则是把状态栏设置为透明或者半透明. 沉浸式状态栏是从android Kitkat(Android 4.4)开始出 ...