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. OpenCV在未知相机内参数情况下的立体图像矫正方法及注意事项

    http://blog.sina.com.cn/s/blog_4298002e01013yb8.html 很多时候我们不知道摄像机的内参数矩阵,并且我们也不太关注内参数到底是多少,因为我们仅仅关心如何 ...

  2. 微信小程序:工具配置 project.config.json

    微信小程序:工具配置 project.config.json 一.项目配置文件project.config.json 小程序开发者工具在每个项目的根目录都会生成一个 project.config.js ...

  3. 2017-2018-1 JaWorld 团队作业--冲刺7

    2017-2018-1 JaWorld 团队作业--冲刺7 冲刺博客 冲刺1 冲刺2 冲刺3 冲刺4 冲刺5 项目完成情况 存在的问题 存在的问题是敌机只设置了一种,没能实现多种敌机的游戏设置. 界面 ...

  4. ubuntu14.04安装CUDA8.0

    ubuntu安装CUDA 因为深度学习需要用到CUDA,所以写篇博客,记录下自己安装CUDA 的过程. 1 安装前的检查 安装CUDA之前,首先要做一些事情,检查你的机器是否可以安装CUDA. 1.1 ...

  5. Python3基础 raise + 指定类型异常+异常的解释 产生特定类型异常

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. [优化]深度学习中的 Normalization 模型

    来源:https://www.chainnews.com/articles/504060702149.htm 机器之心专栏 作者:张俊林 Batch Normalization (简称 BN)自从提出 ...

  7. hdu 2841 Visible Trees 容斥原理

    Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Pr ...

  8. 类的成员变量修饰 const 和static

    类型 初始化方式 类内(声明) 类外(类实现文件) 构造函数中 构造函数的初始化列表 非静态非常量数据成员 N N Y Y 非静态常量数据成员 N N N Y (must) 静态非常量数据成员 N Y ...

  9. 从数组里随机获取N项

    基础知识: 复制数组: (1)循环遍历复制(不推荐) var arry = [1,5,9,7], new_arry = [], n = 0, len = arry.length; for(;n< ...

  10. Ubuntu 分区方安

    方案一: / 40G/boot 200MBswap 1G-2G /home 20G 剩 下的分为几个独立的分区,不用指定挂载点,而是安装完成后修改 /etc/fstab ,将这些区挂载在/home的子 ...