【Lintcode】1871. Maximum Moment

题目地址:

https://www.lintcode.com/problem/maximum-moment/description

给定一个 24 24 24小时制时间( 00 : 00 ∼ 23 : 59 00:00\sim 23:59 00:0023:59),以字符串形式 s s s给出,其中有若干位是问号,问其能代表的最大时间是多少。以字符串形式返回。

分类讨论即可。如果问号出现在 s [ 0 ] s[0] s[0],那么看一下 s [ 1 ] s[1] s[1],如果 s [ 1 ] ∈ { 0 , 1 , 2 , 3 } s[1]\in \{0,1,2,3\} s[1]{0,1,2,3}或者是问号,那么显然 s [ 0 ] s[0] s[0]应该取 2 2 2,否则就取 1 1 1;如果问号出现在 s [ 1 ] s[1] s[1],那么就看一下 s [ 0 ] s[0] s[0],如果 s [ 0 ] = 1 s[0]=1 s[0]=1那么 s [ 1 ] s[1] s[1] 9 9 9,否则取 3 3 3;接下来,如果问号出现在 s [ 3 ] s[3] s[3] s [ 3 ] s[3] s[3] 5 5 5,如果问号出现在 s [ 4 ] s[4] s[4] s [ 4 ] s[4] s[4] 9 9 9。代码如下:

public class Solution {
    /**
     * @param time: a string of Time
     * @return: The MaximumMoment
     */
    public String MaximumMoment(String time) {
        // write your code here
        char[] chars = time.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '?') {
                if (i == 0) {
                    chars[0] = chars[1] == '?' || chars[1] <= '3' ? '2' : '1';
                } else if (i == 1) {
                    chars[1] = chars[0] == '2' ? '3' : '9';
                } else if (i == 3) {
                    chars[3] = '5';
                } else if (i == 4) {
                    chars[4] = '9';
                }
            }
        }
        
        return new String(chars);
    }
}

时空复杂度 O ( 1 ) O(1) O(1)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
torch.maximum函数在PyTorch中不存在。根据提供的引用内容,我们可以看到torch.max()函数的用法和返回结果。torch.max()函数的用法是torch.max(input, dim, keepdim=False)。它返回两个输出,第一个输出是指定维度上的最大值,第二个输出是最大值在该维度上的索引。所以,我们无法提供关于torch.maximum函数的信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [【冰糖Python】PyTorch:最大值 最小值 torch.max() torch.min() torch.maximum() torch.minimum()](https://blog.csdn.net/xiaoxiao_ziteng/article/details/114487441)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [PyTorch中的torch.max()和torch.maximum()的用法详解](https://blog.csdn.net/gongxifacai_believe/article/details/121278401)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [PyTorch的torch.cat用法](https://download.csdn.net/download/weixin_38653040/12850385)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值