155.min-stack

Spread the love

一开始的思路:

第一反应:建一个list,

新增:新增元素append到尾部

弹出:list尾部pop

top:取list尾部首元素

min:每次新进一个人,和当前min对比

问题:

如果当前的min弹出后,min变量没有记忆性,不知道之前存的min是多少

解决:

建一个存min的list,用法和stack一样,如果出队后,还是可以知道上一个最小值是多少

This entry was posted in leetcode. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *