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. 框架面试题:谈谈我对Spring IOC与DI的理解

    IOC是一种叫做“控制反转”的设计思想. 1.较浅的层次——从名字上解析 “控制”就是指对 对象的创建.维护.销毁等生命周期的控制,这个过程一般是由我们的程序去主动控制的,如使用new关键字去创建一个 ...

  2. jQuery--基础知识速查表

    一.jQuery选择器 选择器 实例 选取 * $("*") 所有元素 #id $("#lastname") id="lastname" 的 ...

  3. 简单的Session案例 —— 一次性验证码

    一次性验证码的主要目的就是为了限制人们利用工具软件来暴力猜测密码,其原理与利用Session防止表单重复提交的原理基本一样,只是将表单标识号变成了验证码的形式,并且要求用户将提示的验证码手工填写进一个 ...

  4. Reading——The Non-Designer's Design Book

    看这本书的时候真的好恨没有CS7在手><,不然我百度几张图来模拟下,体验下设计的快感. 人们总是很容易注意到在他们潜意识里存在的东西,比如说这个图:    我们很容易联想到微信,但是3   ...

  5. WCF项目问题1-找不到类型“WCFService.Service1”,它在 ServiceHost 指令中提供为 Service 特性值,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。

    找不到类型“WCFService.Service1”,它在 ServiceHost 指令中提供为 Service 特性值,或在配置元素 system.serviceModel/serviceHosti ...

  6. (转)Entity Framework 5.0系列之自动生成Code First代码

    原文地址:http://www.cnblogs.com/kenshincui/archive/2013/08/29/3290527.html 在前面的文章中我们提到Entity Framework的“ ...

  7. 设计模式05: Prototype 原型模式(创建型模式)

    Prototype 原型模式(创建型模式) 依赖关系的倒置抽象不应该依赖于实现细节,细节应该依赖于抽象.对所有的设计模式都是这样的. -抽象A直接依赖于实现细节b -抽象A依赖于抽象B,实现细节b依赖 ...

  8. 使用Oracle(SQL Plus)

    error: connection as sys should be as SYSDBA or SYSOPER 用户名 :sys 密码:  自己设定的database:ORCLconnect as : ...

  9. Android 学习笔记 文本文件的读写操作

    activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...

  10. php 递归求得目录大小

    /* * 递归求得目录大小 * @param $dir 目录 */ function dirsize($dir){ $allsize = 0; $handle = opendir($dir); whi ...