diff --git a/src/main/java/leetcode/editor/cn/IIQa4I.java b/src/main/java/leetcode/editor/cn/IIQa4I.java new file mode 100644 index 0000000..21e1eee --- /dev/null +++ b/src/main/java/leetcode/editor/cn/IIQa4I.java @@ -0,0 +1,68 @@ +//

请根据每日 气温 列表 temperatures ,重新生成一个列表,要求其对应位置的输出为:要想观测到更高的气温,至少需要等待的天数。如果气温在这之后都不会升高,请在该位置用 0 来代替。

+// +//

 

+// +//

示例 1:

+// +//
+//输入: temperatures = [73,74,75,71,69,72,76,73]
+//输出: [1,1,4,2,1,1,0,0]
+//
+// +//

示例 2:

+// +//
+//输入: temperatures = [30,40,50,60]
+//输出: [1,1,1,0]
+//
+// +//

示例 3:

+// +//
+//输入: temperatures = [30,60,90]
+//输出: [1,1,0]
+// +//

 

+// +//

提示:

+// +// +// +//

 

+// +//

+// 注意:本题与主站 739 题相同: https://leetcode-cn.com/problems/daily-temperatures/

+// +//
Related Topics
  • 数组
  • 单调栈

  • 👍 73
  • 👎 0
  • +package leetcode.editor.cn; + +// 剑指 Offer II 038:每日温度 +public class IIQa4I { + public static void main(String[] args) { + Solution solution = new IIQa4I().new Solution(); + // TO TEST + } + + //leetcode submit region begin(Prohibit modification and deletion) + class Solution { + public int[] dailyTemperatures(int[] temperatures) { + int[] res = new int[temperatures.length]; + int index = temperatures.length - 1; + res[index] = 0; + for (int i = temperatures.length - 2; i >= 0; i--) { + if (temperatures[i] < temperatures[index]) { + res[i] = index - i; + } else { + index = i; + res[i] = 0; + } + } + return res; + } + } +//leetcode submit region end(Prohibit modification and deletion) + +} diff --git a/src/main/java/leetcode/editor/cn/doc/content/IIQa4I.md b/src/main/java/leetcode/editor/cn/doc/content/IIQa4I.md new file mode 100644 index 0000000..3bb3853 --- /dev/null +++ b/src/main/java/leetcode/editor/cn/doc/content/IIQa4I.md @@ -0,0 +1,39 @@ +

    请根据每日 气温 列表 temperatures ,重新生成一个列表,要求其对应位置的输出为:要想观测到更高的气温,至少需要等待的天数。如果气温在这之后都不会升高,请在该位置用 0 来代替。

    + +

     

    + +

    示例 1:

    + +
    +输入: temperatures = [73,74,75,71,69,72,76,73]
    +输出: [1,1,4,2,1,1,0,0]
    +
    + +

    示例 2:

    + +
    +输入: temperatures = [30,40,50,60]
    +输出: [1,1,1,0]
    +
    + +

    示例 3:

    + +
    +输入: temperatures = [30,60,90]
    +输出: [1,1,0]
    + +

     

    + +

    提示:

    + + + +

     

    + +

    + 注意:本题与主站 739 题相同: https://leetcode-cn.com/problems/daily-temperatures/

    + +
    Related Topics
  • 数组
  • 单调栈

  • 👍 73
  • 👎 0
  • \ No newline at end of file