题解 | #递减种子序列#

递减种子序列

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?

全部评论

相关推荐

06-15 18:44
黄淮学院 Java
Lynn012:如果是居民楼还是算了吧,看着有点野呢
点赞 评论 收藏
分享
04-27 08:59
常州大学 Java
牛客139242382号:《两门以上汇编语言》
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务