We need to calculate the LISNumber of a sequence which the
smallest of the number of strictly increasing sequences needed.
So we need to compare number with its neighbor, if the
current is less than neighbor we need to continue.
If the current number is greater
than or equal to the neighbor it is a separate sequence increment the count.
Solution to SRM 585 DIV2 250 Point Problem.
public int calculate(int[] seq)
{
int res=0;
for(int i=0;i<seq.length-1;i++)
{
if(seq[i]<seq[i+1])
{
continue;
}
else if(seq[i]==seq[i+1])
{
res++;
}
else
{
res++;
}
}
return (res+1);
}
|
No comments:
Post a Comment