949. 给定数字能组成的最大时间

 显示英文描述

 
  • 用户通过次数125
  • 用户尝试次数213
  • 通过次数127
  • 提交次数774
  • 题目难度Easy

给定一个由 4 位数字组成的数组,返回可以设置的符合 24 小时制的最大时间。

最小的 24 小时制时间是 00:00,而最大的是 23:59。从 00:00 (午夜)开始算起,过得越久,时间越大。

以长度为 5 的字符串返回答案。如果不能确定有效时间,则返回空字符串。

示例 1:

输入:[1,2,3,4]
输出:"23:41"

示例 2:

输入:[5,5,5,5]
输出:""

提示:

  1. A.length == 4
  2. 0 <= A[i] <= 9
class Solution {
public:
string ans = "";
string largestTimeFromDigits(vector<int>& A) {
check(A[],A[],A[],A[]);
check(A[],A[],A[],A[]);
check(A[],A[],A[],A[]);
check(A[],A[],A[],A[]);
check(A[],A[],A[],A[]);
check(A[],A[],A[],A[]);
return ans;
} void check(int a,int b,int c,int d){
string first = best(a,b,);
string second = best(c,d,);
if(first == ""||second == "")return;
string cand = first + ":" + second;
if(bijiao(cand,ans))ans = cand;
return;
} bool bijiao(string cand,string ans){
if(ans == "")return ;
int a = (cand[]-'')* + (cand[]-'')* + (cand[]-'')* + (cand[]-'');
int b = (ans[]-'')* + (ans[]-'')* + (ans[]-'')* + (ans[]-'');
return a > b;
}
string caonima(int num){
string res = "";
res += (num+'');
return res;
} string best(int a,int b,int limit){
int res = max(a*+b<limit ? a*+b:-,b*+a<limit ? b*+a:-);
if(res >= ) return to_string(res);
else if(res>= && res<)return caonima(res);
else return "";
}
};

_再也不会做这种恶心死了的题,烦死了快,各种边界条件,输出格式!!

Leetcode 949. 给定数字能组成的最大时间的更多相关文章

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

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

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

  3. LeetCode 34 Search for a Range (有序数组中查找给定数字的起止下标)

    题目链接: https://leetcode.com/problems/search-for-a-range/?tab=Description   Problem: 在已知递减排序的数组中,查找到给定 ...

  4. leetcode 12题 数字转罗马数字

    leetcode 12题 数字转罗马数字 答案一:我的代码 代码本地运行完全正确,在线运行出错 class Solution { public: string intToRoman(int num) ...

  5. [LeetCode] 681. Next Closest Time 下一个最近时间点

    Given a time represented in the format "HH:MM", form the next closest time by reusing the ...

  6. mysql学习1:数据类型:数字型,日期和时间,字符串类型(总结)

    mysql数据类型:数字型,日期和时间,字符串类型 摘要 MySQL中定义数据字段的类型对数据库的优化是非常重要的: MySQL支持多种类型,大致可以分为三类,如下. 数字类型 整数:tinyint. ...

  7. linux time-统计给定命令所花费的总时间

    推荐:更多linux 性能监测与优化 关注:linux命令大全 time命令用于统计给定命令所花费的总时间. 语法 time(参数) 参数 指令:指定需要运行的额指令及其参数. 实例 当测试一个程序或 ...

  8. LeetCode.2-两个数字相加(Add Two Numbers)

    这是悦乐书的第340次更新,第364篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第1题(顺位题号是2).给定两个非空链表,表示两个非负整数. 数字以相反的顺序存储, ...

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

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

随机推荐

  1. BZOJ 4399 魔法少女LJJ(线段树合并)

    题意 https://www.lydsy.com/JudgeOnline/problem.php?id=4399 思路 码农题,需要一定代码功底.方法很暴力,先将权值离散,表示在线段树里储存的位置,每 ...

  2. Derek解读Bytom源码-P2P网络 地址簿

    作者:Derek 简介 Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchain/bytom ...

  3. Qt button和buttons区别

    假设我的鼠标左键已经按下.若移动鼠标,会发生的move事件,button返回Qt::NoButton,buttons返回LeftButton.再按下右键,会发生press事件,button返回Righ ...

  4. getAttribute与getParameter的区别

    1.getParameter得到的是字符串,其取值源于jsp页面,从jsp页面中接受一个存在的参数,多用于servlet中,用于判断业务的类型和跳转页面.如: request.getParameter ...

  5. Gym 101617J Treasure Map(bfs暴力)

    http://codeforces.com/gym/101617/attachments 题意:给出一个图,每个顶点代表一个金矿,每个金矿有g和d两个值,g代表金矿初始的金子量,d是该金矿每天的金子量 ...

  6. 添加删除tag

    为某个分支打tag git tag -a v1. 9fceb02 删除tag git tag -d test_tag git push origin --delete tag test_tag 推送: ...

  7. 封装微信小程序支付

    <?php /** * User: Eden * Date: 2019/3/21 * 共有内容 */ namespace Common\Service; use Think\Exception; ...

  8. 本地Windows上安装 MySQL数据库

    1.首先下载mysql安装文件,下载地址:https://dev.mysql.com/downloads/mysql/ 2.将下载下来的压缩包解压到本地一个文件夹中 3.在文件根目录下新增my.ini ...

  9. The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

    关于出现这个·问题的原因貌似也是多种多样的? 在stack overflow上的帖子如下:https://stackoverflow.com/questions/43186315/tomcat-404 ...

  10. keys(),values()和items()

    a={'a':11,'b':'bb','c':321}for x in a.items(): print(x)  # 每条都输出来print("------------")for ...