1130. Minimum Cost Tree From Leaf Values

T: O(n^2), every round finds the smallest index(from n numbers), then count pre, post, and do n times. so n^2

S: O(n), removeElement needs n space to copy

Mono Stack

T: O(n)

S: O(n)

Last updated

Was this helpful?