Back to course home
0% completed
Vote For New Content
Another Implement Using GO + Array
Nghĩa Huỳnh Trung
Jun 24, 2025
func (this *Solution) nextLargerElement(arr []int) []int { res := make([]int, len(arr)) stack := make([]int, 0) for i := len(arr) - 1; i >= 0; i-- { length := len(stack) for length > 0 { if arr[i] < stack[length-1] { res[i] = stack[length-1] stack = append(stack, arr[i]) break } length-- } if length == 0 { res[i] = -1 stack = append(stack, arr[i]) continue } } return res }
0
0
Comments
Comments
On this page