找LeetCode上简单的题目来撑过30天啦(DAY21)

不知道要打什麽,直接开始

题号:739 标题:Daily Temperatures 难度:Medium

Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.

Example 1:
Input: temperatures = [73,74,75,71,69,72,76,73]
Output: [1,1,4,2,1,1,0,0]

Example 2:
Input: temperatures = [30,40,50,60]
Output: [1,1,1,0]

Example 3:
Input: temperatures = [30,60,90]
Output: [1,1,0]

Constraints:
• 1 <= temperatures.length <= 105
• 30 <= temperatures[i] <= 100

我的程序码

class Solution {
    public int[] dailyTemperatures(int[] temperatures) {
        int[] result = new int[temperatures.length];
        Arrays.fill(result, 0);
        int i,j,k,count=0;
        for(i=0;i<temperatures.length-1;i++){
            count = 1;
            if(temperatures[i]<temperatures[i+1]){
                result[i] = 1;
                continue;
            }
            for(j=i+1;j<temperatures.length;j++){
                if(temperatures[i]<temperatures[j]){
                    result[i] = count;
                    break;
                }
                count++;
            }
        }
        return result;
    }
}

花比较久的时间
又是Time Limit Exceeded,我在第二层for前加上,if(temperatures[i]<temperatures[i+1])判断,就过了!?

DAY21心得
我真的很常遇到Time Limit Exceeded,我想是我得思考还不够精准?真的很钦佩大神们都有很多更聪明的解法,慢慢学习罗


<<:  分布式可观测性 Structured Log

>>:  Flutter体验 Day 28-flame JoystickComponent

【第22天】训练模型-模型组合与辨识isnull(三)

摘要 交叉验证不同方法组合的模型准确率 1.1 参数说明 1.2 程序码 选择模型组合方法 2.1 ...

[职场]掌握薪水谈判的秘诀,取得自己应有的报酬 & 完赛感言

如果你是一个有野心且不安於现状的人,薪水谈判是你一定要去做的事情。 在阅读这篇文章前,你可以先思考...

[day8] 实务搭建 - 储值卡,系统概述

将钱先放到你的金卡,可以享大大大优惠,点点卡、OO卡、XX卡、网咖等都是先储值再消费,这边将实作一个...

Day1 - 导读 带你认识资料科学所需套件

先备知识: 基本python能力 : 熟悉各基本型态,认识串列、字典、函式、class 了解深度学习...

离职倒数20天:我想要创造新的连结,让我可以不要在这条新的路上这麽无助

每年生日刚好是伊豆诸岛的旺季开始前一周,通常天气宜人,海水清澈到可以目视钓鱼,离东京只要搭船三小时,...