jack.watermelon
BAN USERyeah that sounds correct
- jack.watermelon April 24, 2010creating a table will not be efficient, a integer can be of 4 bytes, thus having value till 2^32, we will have to maintain such a big table
- jack.watermelon April 24, 2010yes a binary search tree would be more efficient
- jack.watermelon April 24, 2010for normal data types, pass by value and reference dont have any memory constraints, but when passing objects once should use reference as by value if the object is big can take loads of time
- jack.watermelon April 21, 2010Hi,
also we can solve by taking the smallest and biggest element in the array, and the max difference would be answer
O(n) solution
Can't we just declare the new constructor to be private? also is this is abstract class, cause in the first place we cannot create object of it anywaz
- jack.watermelon April 20, 2010well, we can have
class cards
{
private:
int cardsNumber[12];
string cardsColor;
public:
cards(string _cardsColor)
{
cardsColor = _cardsColor;
}
}
void main()
{
cards hearts = new hearts("Red hearts");
cards diamonds = new diamonds ("Red diamonds");
// and so on, we can give ID for different colors and we can also incialize the numbers
we should find all the factors of the two numbers,
- jack.watermelon April 24, 2010for (i=0;i<n;i++)
{
if(n%i ==0)
factor[j] = n;
j++;
}
factor would be array that is storing all factors of the number. similarly we can get for second number. one thing we can check is whether the number is even or odd, if its odd, then 2,4,6,8,0 or any even number cannnot be a factor of that and will save half of the computation.
then we can check the length of factor array and start with the one that has less elements, because of our loop, the factor array will contain elements in sorted manner. we can then check from the smaller array and then return the answer.
please give comments if this sounds ok or not