impl Solution { pubfnnext_greater_elements(nums: Vec<i32>) -> Vec<i32> { let n = nums.len(); letmut ans = vec![-1; n]; letmut stack: Vec<usize> = vec![];
for i in0..2 * n { let num = nums[i % n]; while !stack.is_empty() { let top = stack.last().unwrap().clone(); if nums[top] >= num { break; } ans[top] = num; stack.pop(); } if i < n { stack.push(i); } }