publicint[] dailyTemperatures(int[] temperatures) { int[] stack =newint[temperatures.length]; inttop = -1; int[] ret =newint[temperatures.length]; for(inti =0; i < temperatures.length; i++) { while(top > -1&& temperatures[i] > temperatures[stack[top]]) { intidx = stack[top--...
Note: The length of temperatures will be in the range [1, 30000]. Each temperature will be an integer in the range [30, 100]. 这道题不能直接暴力求解,会超时(我试过了TnT),需要利用到栈后进先出的特性。 1classSolution:2defdailyTemperatures(self, T: List[int]) ->List[int]:3stack =[]...
"For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby." Algorithms #TitleSolutions...
1716 Calculate Money in Leetcode Bank Solution Easy Math, Greedy 1711 Count Good Meals Solution Medium Array, HashTable, Two Pointers 1710 Maximum Units on a Truck Solution Easy Greedy, Sort 1708 Largest Subarray Length K Solution Easy Array, Greedy 1704 Determine if String Halves Are Alike Solu...
class Solution { public int[] dailyTemperatures(int[] T) { //典型的mono stack问题 //之前我们需要求ple/nle 现在我们需要求next larger element. //思路上并没有什么不同 LinkedList<int[]> nle = new LinkedList<>(); int n = T.length; ...
Leetcode 739. Daily Temperatures 简单题,梳理一下相邻两数之间的关系就行. classSolution(object):defdailyTemperatures(self, T):""":type T: List[int] :rtype: List[int]"""size=len(T) dp=[x*0forxinrange(size)]foriinrange(size-2,-1,-1):ifT[i]==T[i+1]:ifdp[i+1]==0:...
Note: The length oftemperatureswill be in the range[1, 30000]. Each temperature will be an integer in the range[30, 100]. classSolution(object):defdailyTemperatures(self, T):""":type T: List[int] :rtype: List[int]"""l= [0] *len(T) ...
Check out here: https://travis-ci.org/github/fishercoder1534/Leetcode/pull_requests and look for your PR build. Fork this repo Clone your forked repo (git clone https://github.com/YOUR_GITHUB_USERNAME/Leetcode.git) onto your local machine cd into your cloned directory, create your feature...
AC Python:1 class Solution: 2 def dailyTemperatures(self, temperatures: List[int]) -> List[int]: 3 n = len(temperatures) 4 stk = [] 5 res = [0] * n 6 for i in range(n): 7 while stk and temperatures[stk[-1]] < temperatures[i]: 8 top = stk.pop() 9 res[top] = i ...