My Solution.

Almost same as above but the flag is set by using bits.

#define SETFLAG(flag, pos) (flag=flag | (1<<pos-1))
#define IS_FLAG_SET(flag,pos) (flag & (1<<pos-1))

int remove_dup(int n)
{
        int temp=0, temp2=0;
        unsigned int flag=0;

        /*
         * Reverse the number
         */
        while (n>0 && (temp=temp*10 + n%10), n=n/10);

        /*
         * Find duplicates by setting the bits in the flag
         */
        n=temp;
        temp=0;
        while (n>0) {
                temp2=n%10;
                if(!IS_FLAG_SET(flag, temp2)) {
                        temp=temp*10 + temp2;
                        SETFLAG(flag, temp2);
                }
                n=n/10;
        }
        return temp;
}

-- 
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.

Reply via email to