public class Solution
{
public int getHeight(int []nums, int n)
{
int []dp = new int[n];
int len = 1;
dp[0] = nums[0];
for(int i=1; i<n; i++)
{
int pos = getPos(dp, nums[i], len);
if(pos < len) dp[pos] = nums[i];
else dp[len++] = nums[i];
}
return len;
}
public int getPos(int []dp, int num, int len)
{
int left = 0;
int right = len-1;
while(left <= right)
{
int mid = (left+right)/2;
if(num == dp[mid]) return mid;
else if(num > dp[mid]) left = mid+1;
else right = mid-1;
}
return left;
}
}