here is solution for non-decreasing number using simple recursion.
static int min=0;
static int flag=0;
int nonDec(int num)
{
if(num==0)
{
return 0;
}
nonDec(num/10);
if(flag==1)
{
return -1; // not a non-decreasing number.
}
if(min <= (num%10))
{
min=num%10;
}
else
{ flag=1;
return -1;
}
return 1; // is a non-decreasing number.
}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.