package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/daily-temperatures/
 */
public class Problem739 {
    public int[] dailyTemperatures(int[] temperatures) {
        int[] result = new int[temperatures.length];
        int i = 0;
        int j = 1;
        int count = 1;
        while (i < temperatures.length) {
            if (j == temperatures.length) {
                count = 1;
                i++;
                j = i + 1;
                continue;
            }
            if (temperatures[i] < temperatures[j++]) {
                result[i++] = count;
                count = 1;
                j = i + 1;
            } else {
                count++;
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Problem739 prob = new Problem739();
        System.out.println(Arrays.toString(prob.dailyTemperatures(new int[]{73, 74, 75, 71, 69, 72, 76, 73}))); // [1, 1, 4, 2, 1, 1, 0, 0]
        System.out.println(Arrays.toString(prob.dailyTemperatures(new int[]{73, 73}))); // [0, 0]
        System.out.println(Arrays.toString(prob.dailyTemperatures(new int[]{73, 72, 71, 70}))); // [0, 0, 0, 0]
        System.out.println(Arrays.toString(prob.dailyTemperatures(new int[]{55, 38, 53, 81, 61, 93, 97, 32, 43, 78}))); // [3,1,1,2,1,1,0,1,1,0]
    }
}

@@ -36,16 +36,40 @@
 .Arrays;
+%0Aimport java.util.Stack;
 %0A%0A/**%0A *
@@ -271,19 +271,313 @@
     
-int i = 0;%0A
+Stack%3CInteger%3E stack = new Stack%3C%3E();%0A        int j = 1;%0A        for (int i = 0; i %3C temperatures.length - 1; i++) %7B%0A            if (temperatures%5Bi%5D %3C temperatures%5Bj%5D) %7B%0A                result%5Bi%5D = j - i;%0A            %7D else %7B%0A                stack.push(i);%0A            %7D%0A        %7D%0A%0A//        int i = 0;%0A//
     
@@ -583,32 +583,34 @@
      int j = 1;%0A
+//
         int coun
@@ -608,32 +608,34 @@
  int count = 1;%0A
+//
         while (i
@@ -652,32 +652,34 @@
 tures.length) %7B%0A
+//
             if (
@@ -702,24 +702,26 @@
 s.length) %7B%0A
+//
             
@@ -727,32 +727,34 @@
      count = 1;%0A
+//
                 
@@ -754,24 +754,26 @@
        i++;%0A
+//
             
@@ -779,32 +779,34 @@
      j = i + 1;%0A
+//
                 
@@ -815,16 +815,18 @@
 ntinue;%0A
+//
         
@@ -823,32 +823,34 @@
 //            %7D%0A
+//
             if (
@@ -884,24 +884,26 @@
 res%5Bj++%5D) %7B%0A
+//
             
@@ -927,16 +927,18 @@
  count;%0A
+//
         
@@ -952,24 +952,26 @@
  count = 1;%0A
+//
             
@@ -981,24 +981,26 @@
  j = i + 1;%0A
+//
             
@@ -1000,32 +1000,34 @@
        %7D else %7B%0A
+//
                 
@@ -1035,16 +1035,18 @@
 ount++;%0A
+//
         
@@ -1043,32 +1043,34 @@
 //            %7D%0A
+//
         %7D%0A      
@@ -1314,32 +1314,34 @@
  2, 1, 1, 0, 0%5D%0A
+//
         System.o
@@ -1418,24 +1418,26 @@
 ; // %5B0, 0%5D%0A
+//
         Syst
@@ -1536,16 +1536,18 @@
 , 0, 0%5D%0A
+//
         

Update problem 739