Tarunjit Singh
BAN USERI thinks it perfectly make sense ... we are not making the compiler compare the numbers twice .... we are checking the it against a value now and the comparison will be done once only.
Please let me know if you still think there is something wrong here.
I am not getting what exactly are you trying to say.
can you please explain what are you trying to do by counting the numbers not divisible by 3 ?
Naveen i think you need to review you code again ...
return(max(hasPathSum(node->left,sum),hasPathSum(node->left,sum)));
//is same as ..
return (hasPathSum(node->left,sum);
why are you using max function .. i think you shud not use it.
- Tarunjit Singh May 24, 2012bool btree::hasSum(node* temp, int s)
{
//same as hasPathSum function
if (s==0)
return true;
else if (temp != NULL && s>=0)
return (hasSum(temp->left, s-temp->value) || hasSum(temp->right,s-temp->value));
else
return false;
}
int main()
{
cout<<"Decimal - 3"<<endl;
int i = 0, j = 0 , temp;
int n = 14 ;// Input your number here
while(i<=n)
{
temp = i;
// cout<<"In while1 - j :"<<j<<" temp :"<<temp<<endl;
bool Flag = false;
while(temp>0 && !Flag)
{
// cout<<" temp :"<<temp<<endl;
if(temp%10 == 3)
{
j++;
// cout<<" In while2 - j :"<<j<<endl;
Flag = true;
}
temp = temp/10;
}
i++,j++;
}
cout<<"j : "<<j-1<<endl;
return 0;
}
@saurabh ... Why to subtract ?
I think if you are removing a element from the Decimal System .. then we should add (not subtract) the number of times that specific element was present before the given number.
like ... 3 will become 4 and the number system will look like .. 0,1,2,4,5 ... 12,14, 15, .. 29,40 ... and so on ...
@saurabh ... Why to subtract ?
I think if you are removing a element from the Decimal System .. then we should add (not subtract) the number of times that specific element was present before the given number.
like ... 3 will become 4 and the number system will look like .. 0,1,2,4,5 ... 12,14, 15, .. 29,40 ... and so on ...
@rdo ... I cannot understand what are trying to do with the pointers .. are you calculating the min distance??
- Tarunjit Singh May 28, 2012What i think is .. we had to find the point from where the distance is minimum to every other given point .. which should be the Median.
Please elaborate if you are doing anything else ?