HTMLify

LeetCode - Next Greater Node In Linked List - Go
Views: 6 | Author: abh
// @leet start
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func nextLargerNodes(head *ListNode) []int {
	var ans []int
	th := head
	for th != nil {
		th2 := th.Next
		ans = append(ans, 0)
		for th2 != nil {
			if th2.Val > th.Val {
				ans[len(ans)-1] = th2.Val
				break
			}
			th2 = th2.Next
		}
		th = th.Next
	}
	return ans
}
// @le

Comments