DAY 58每日温度12345678910111213funcdailyTemperatures(temperatures []int)[]int{n :=len(temperatures)stack :=make([]int,0, n)ans :=make([]int, n)fori, temperature :=rangetemperatures {forlen(stack) >0&& temperature > temperatures[stack[len(stack)-1]] {ans[stack[len(stack)-1]] = i - stack[len(stack)-1]stack = stack[:len(stack)-1]}stack =append(stack, i)}returnans}下一个更大元素 I不同之处是栈中存的是元素的值123456789101112131415161718192021funcnextGreaterElement(nums1 []int, nums2 []int)[]int{stack :=make([]int,0,len(nums2))m :=map[int]int{}for_, num :=rangenums2 {forlen(s
...
继续阅读
(96)