DP C# version


  • 0
    S
    public class Solution {
        public int LengthOfLIS(int[] nums) 
        {
            if(nums == null || nums.Count() == 0)
                return 0;
            var dp = new List<int>();
            foreach(var num in nums)
            {
                if(!dp.Any() || dp[dp.Count()-1] < num)
                {
                    dp.Add(num);
                }
                else
                {
                    var index = dp.BinarySearch(num);
                    if(index < 0)
                    {
                        index = ~index;
                    }
                    dp[index] = num;
                }
            }
            return dp.Count();
        }
    }
    

Log in to reply
 

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