登录
  • #刷题
  • #二分/排序/搜索

什么‌‌‍‍‌‍‍‌‍‌‍‍‌‌‌‌‍‌‍‍‍‍‍‌‌‍‌‌‌‍‍‍时候会用到单调栈(递增递减栈)的思想

samuelling
9539
20
自己在学习栈的时候接触到了一种算法叫单调栈(递增递减栈)。最典型的问题就是largest rectangle in histogram。但是后来自己做题发现单调栈的应用非常多,思路也很巧妙,但是不知道这个思路解决问题的共性是什么。比如下面这两个问题,为什么我们会想到用单调栈呢?

Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.

Given string A representative a positive integer which has N digits, remove any k digits of the number, the remaining digits are arranged according to the original order to become a new positive integer.

Find the smallest integer after remove k digits.
20条回复
热度排序

发表回复