Easy and short nlog(n) approach in Java


  • 0
    P

    public class Solution {
    public int lengthOfLIS(int[] nums) {
    int n=nums.length;
    int max = 0;
    int I[]= new int[n+1];
    Arrays.fill(I,Integer.MAX_VALUE);
    I[0] = Integer.MIN_VALUE;
    for(int i=0;i<n;i++){
    int ind = Arrays.binarySearch(I ,nums[i]);
    if(ind <0)
    ind = -ind-1;
    I[ind] = nums[i];
    if(max < ind)
    max =ind;
    }
    return max;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.