Clicky

Leetcode 739 "Daily Temperatures"

January 1, 0001

739. Daily Temperatures

Result

Runtime: 1001 ms, faster than 7.45% of Java online submissions for Daily Temperatures.

Memory Usage: 47.1 MB, less than 66.06% of Java online submissions for Daily Temperatures.

class Solution {
    public int[] dailyTemperatures(int[] temperatures) {
        for(int i=0; i<temperatures.length; i++) {
            int count = 0;
            boolean flag = false;
            for(int j=i; j<temperatures.length; j++) {
                if(temperatures[j] <= temperatures[i]) {
                    count = count + 1;
                } else {
                    flag = true;
                    break;
                }
            }
            temperatures[i] = flag ? count : 0;
                
        }
        return temperatures;
    }
}