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 }

原文地址:https://www.cnblogs.com/sheepcore/p/12395404.html

时间: 2024-10-30 12:58:34

LeetCode-739 Daily Temperatures Solution (with Java)的相关文章

[栈] leetcode 739 Daily Temperatures

problem:https://leetcode.com/problems/daily-temperatures/ 一道使用单调栈维护(递减序列)的题目,比较简单. class Solution { public: vector<int> dailyTemperatures(vector<int>& T) { stack<int> sta; int n = T.size(); vector<int> res(n, 0); for (int i = 0

739. Daily Temperatures - LeetCode

Question 739.?Daily Temperatures Solution 题目大意:比今天温度还要高还需要几天 思路:笨方法实现,每次遍历未来几天,比今天温度高,就坐标减 Java实现: public int[] dailyTemperatures(int[] temperatures) { int[] ans = new int[temperatures.length]; for (int i = 0; i<temperatures.length; i++) { int highId

739. Daily Temperatures

https://leetcode.com/problems/daily-temperatures/description/ class Solution { public: vector<int> dailyTemperatures(vector<int>& temperatures) { stack<int> st; vector<int> res(temperatures.size()); for (int i = temperatures.si

LeetCode 739:每日温度 Daily Temperatures

题目: 根据每日 气温 列表,请重新生成一个列表,对应位置的输入是你需要再等待多久温度才会升高超过该日的天数.如果之后都不会升高,请在该位置用 0 来代替. 例如,给定一个列表 temperatures = [73, 74, 75, 71, 69, 72, 76, 73],你的输出应该是 [1, 1, 4, 2, 1, 1, 0, 0]. Given a list of daily temperatures T, return a list such that, for each day in

[LeetCode] Daily Temperatures 日常温度

Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead. For example, given the

LeetCode - Daily Temperatures

Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead. For example, given the

leetcode 119 Pascal&#39;s Triangle II ----- java

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. Note:Could you optimize your algorithm to use only O(k) extra space? 上一道题的延伸版,就是直接求出第k行的数,要求用o(k)的空间复杂度. 也是直接相加就可以了. public class Solution { pub

LeetCode算法题-Rotate String(Java实现)

这是悦乐书的第317次更新,第338篇原创 在开始今天的算法题前,说几句,今天是世界读书日,推荐两本书给大家,<终身成长>和<禅与摩托车维修艺术>,值得好好阅读和反复阅读. 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第186题(顺位题号是796).给定两个字符串A和B,在A上进行移位操作,规则是将A最左边的字符移动到最右边去.例如,如果A ='abcde',那么在A上移位一次后,它将是'bcdea'.当且仅当A在A上移位一定次数后可以变为B时返回True.

【leetcode】solution in java——Easy2

转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6410409.html 6:Reverse String Write a function that takes a string as input and returns the string reversed. 此题:字符串反转题. 思路:此题大一学C++的时候上机题就做过了,当时思路是:把String转化为char[],从尾到头遍历一次倒序地把字符复制到另一个数组(从头到尾),然后把新数组toStrin