ashpiy
BAN USER
We can have some simpler one.
lets have one example.
"25631"
Equation can be: 25+6=31.
follow the below steps
1) 2+5=631 (no 7 != 631 also 7<631)
2) 2+56=31 (no 58 !=31 also 58>31, break the loop here itself)
3) Now instead of 2 take 25 and start again.
25+6=31 (yes 31==31, break the loop again).
Above steps can be converted into code.
This is 3 iteration only. but we can improve this approach.
1) first take 4 and 4 (keep 2 separate)
if both are equal then measure these 2 only. (only 2 iteration)
2) if those 4 and 4 are not equal then take lighter one.
now instead of 2 and 2 take any 1 and 1. if they are unequal, it solves the problem. (again only 2 iterations).
3) now if 1 and 1 are also equal then compare rest of two.
this is the worst case when we need 3 iteration.
This is not the proper answer.
Shallow copy: In this type of copy only primitive members of the objects are copied. In this case cloned object refer to the same object for which clone has been invoked, as only the reference is copied not the whole object.
Deep copy: In the deep copy member objects are also copied along with the primitive types, to support deep copy we need to override the clone method of Object class, because in original clone() method it is not supported as it is defined in Object class and and at that level we don't know whether our class will have any non-primitive member or not.
For addition, instead of reversing the link list, shouldn't we make the exact no by traversing through the list. because if we reverse the link list we are changing the input also.
- ashpiy November 09, 2010And building the exact number is easier than reversing the link list.
take your example itself.
1->2->3.
no will be= (1*10+2)*10+3=123
1->2
no will be= 1*10+2=12
now add the nos= 123+12=135.
Store the resulting number in Link list. that can be done in reverse order. (because we will do divide by 10).
then reverse this Link List.
In this approach we don't have to worry about carry over also.
Please suggest.