專賣衣服的購物平臺(tái)seo的課誰講的好
目錄
學(xué)習(xí)目標(biāo)
學(xué)習(xí)內(nèi)容
?739.?每日溫度?
??496.下一個(gè)更大元素?I??
學(xué)習(xí)目標(biāo)
- ?739.?每日溫度?
- ?496.下一個(gè)更大元素?I??
學(xué)習(xí)內(nèi)容
?739.?每日溫度?
739. 每日溫度 - 力扣(LeetCode)
https://leetcode.cn/problems/daily-temperatures/
class Solution:def dailyTemperatures(self, temperatures: List[int]) -> List[int]:n = len(temperatures)res = [0]*nstack = []for i in range(n):while stack and temperatures[stack[-1]]<temperatures[i]:e = stack.pop()res[e] = i-estack.append(i)return res
??496.下一個(gè)更大元素?I??
496. 下一個(gè)更大元素 I - 力扣(LeetCode)
https://leetcode.cn/problems/next-greater-element-i/
from collections import defaultdict
class Solution:def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:n = len(nums1)m = len(nums2)dic = defaultdict()stack = []for i in range(m):while stack and stack[-1]<nums2[i]:e = stack.pop()dic[e]=nums2[i]stack.append(nums2[i])for i in range(n):nums1[i]=dic[nums1[i]] if nums1[i] in dic else -1return nums1
?