不知道要打什麼,直接開始
題號: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.
我的程式碼
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,我想是我得思考還不夠精準?真的很欽佩大神們都有很多更聰明的解法,慢慢學習囉