> For the complete documentation index, see [llms.txt](https://851958789.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://851958789.gitbook.io/notes/0556_next_greater_element_iii/slt.md).

# 思路1 利用单调栈

* 首先，从低到高位依次递增的，返回-1， 如44332211
* 从低位到高位遍历，找到低位比高位大的最小值。如12443111，则走到2的时候，低位就有比高位大的了（4和3），然后选取最小的，也就是3，和2交换，变成1344211
* 最后再把3后面的反转一下，1311244

为了找到3，我们维护一个单调递增的栈
