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: [1,2,3,4]
Output: "23:41"

Example 2:

Input: [5,5,5,5]
Output: ""

Note:

  1. A.length == 4
  2. 0 <= A[i] <= 9

给四个数字,组合成时间看得到的最大值是多少

全排列过去,把不符合规定的筛选掉就OK

class Solution {
public:
string largestTimeFromDigits(vector<int>& A) {
int x[];
for(int i=;i<;i++){
x[i]=A[i];
}
string u = "";
sort(x,x+);
do{
if(x[]>=){
continue;
}
if(x[]==){
if(x[]>){
continue;
}
}
if(x[]>=){
continue;
} int H,M;
u = "";
u += to_string(x[]);
u += to_string(x[]);
u +=':';
u += to_string(x[]);
u += to_string(x[]);
cout<<u<<endl;
cout<<x[]<<" "<<x[]<<" "<<x[]<<" "<<x[]<<endl;
}while(next_permutation(x,x+));
return u;
}
};

113th LeetCode Weekly Contest Largest Time for Given Digits的更多相关文章

  1. 119th LeetCode Weekly Contest Largest Perimeter Triangle

    Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, ...

  2. 113th LeetCode Weekly Contest Reveal Cards In Increasing Order

    In a deck of cards, every card has a unique integer.  You can order the deck in any order you want. ...

  3. 113th LeetCode Weekly Contest Flip Equivalent Binary Trees

    For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left a ...

  4. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  5. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

  6. LeetCode Weekly Contest 23

    LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...

  7. Leetcode Weekly Contest 86

    Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...

  8. LeetCode Weekly Contest

    链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...

  9. 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...

随机推荐

  1. 11-内涵段子-爬虫(python+正则)

    爬取内涵段子,使用正则进行简单处理: #_*_ coding: utf-8 _*_ ''' Created on 2018年7月14日 @author: sss function:爬去内涵段子(静态网 ...

  2. TTS技术

    一.简介 TTS技术,TTS是Text To Speech的缩写,即"从文本到语音".它将计算机自己产生的.或外部输入的文字信息转变为可以听得懂的.流利的汉语口语(或者其他语言语音 ...

  3. Java——操作Excel表格,读取表格内容

    JAVA EXCEL API:是一开放源码项目,通过它Java开发人员可以读取Excel文件的内容.创建新的Excel文件.更新已经存在的Excel文件.使用该API非Windows操作系统也可以通过 ...

  4. EF 常见语句以及sql语句简单 后续继续添加

    1.注意级联删除的时候数据库的外键要设置为开启级联删除,(数据库里sqlserver的外键修改的时候,可以看到级联删除和级联更新) using System;using System.Collecti ...

  5. Java集合框架---重构设计

    面向接口编程: 接口类型 变量 =new 实现类(); List  list=new ArrayList(); --------------------------------------- List ...

  6. Java 线程的通讯--生产者和消费者

    package 生产者和消费者; //消费者 public class Customer implements Runnable { private Share_resources rescource ...

  7. 原型(Prototype)模式

    一. 原型(Prototype)模式 原型模式的用意是:通过给出一个原型对象来指明所要创建的对象类型,然后用复制这个原型对象的办法创建出更多的同类型对象. 从孙大圣的手段谈起 孙悟空在与黄风怪的战斗中 ...

  8. 使用CodeMaid自动程序排版[转]

    前言 「使用StyleCop验证命名规则」这篇文章,指引开发人员透过StyleCop这个工具,来自动检验项目中产出的程序代码是否合乎命名规则. [Tool] 使用StyleCop验证命名规则 但是在项 ...

  9. Ext.Net安装和应用

    1.最新版本 2.打开文件,将包含以下文件:   Ext.Net.dll  Ext.Net.Utilities.dll  Ext.Net.xml  Newtonsoft.Json.dll  Newto ...

  10. angular 重定向路由

    const routes: Routes = [ { path: '', redirectTo: '/home', pathMatch: 'full' }, { path: 'home', compo ...