题解 | #递减种子序列#
递减种子序列
https://www.nowcoder.com/practice/708a3a8603274fc7b5732c5e73617203
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param seeds int整型一维数组 * @return int整型 */ public int lengthOfLIS (int[] seeds) { // write code here //单调栈 Stack<Integer> sta=new Stack<Integer>(); int stackFloors=0; int max=0; for(int i=0;i<seeds.length;i++){ while(!(sta.isEmpty())&&sta.peek()<=seeds[i]){ sta.pop(); stackFloors--; } sta.push(seeds[i]); stackFloors++; max=max>stackFloors?max:stackFloors; } return max; } }
这不就一个单调栈么,为什么要搞dp?