Java实现-最长上升子序列

来源:互联网 发布:linux 查看权限 编辑:程序博客网 时间:2024/06/01 09:18


public class Solution {    /**     * @param nums: The integer array     * @return: The length of LIS (longest increasing subsequence)     */    public int longestIncreasingSubsequence(int[] nums) {        // write your code here        if(nums.length==0){return 0;}int dp[]=new int[nums.length];for(int i=0;i<nums.length;i++){dp[i]=1;for(int j=0;j<i;j++){if(nums[i]>nums[j]&&dp[j]+1>dp[i])dp[i]=dp[j]+1;}}int max=Integer.MIN_VALUE;for(int i=0;i<nums.length;i++){max=Math.max(max, dp[i]);}return max;    }}


原创粉丝点击