LeetCode-739 Daily Temperatures Solution (with Java)

1. Description:

2.Solutions:

 1 /**
 2  * Created by sheepcore on 2019-05-07
 3  */
 4 class Solution {
 5     public int[] dailyTemperatures(int[] T) {
 6         int[] res = new int[T.length];
 7         for(int i = 0; i < T.length -1; i++){
 8             boolean hasWarmerDay = false;
 9             for(int j = i + 1; j < T.length; j++){
10                 if(T[i] < T[j]){
11                     res[i] = j - i;
12                     hasWarmerDay = true;
13                     break;
14                 }
15             }
16             if(!hasWarmerDay)
17                 res[i] = 0;
18         }
19         res[T.length - 1] = 0;
20         return res;
21         }
22 }

 

 

posted @ 2020-03-02 14:13  SheepCore  阅读(145)  评论(0编辑  收藏  举报