My solution.

int f(int n) {
    if (n <= 0) return n;
    int digits = (int)log10(n) + 1;
    int m = 0;
    int flag[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    for (int i = digits - 1; i >= 0; --i) {
        int p = (int)pow(10.0, i);
        int d = n / p;
        n %= p;
        if (flag[d] > 0) continue;
        flag[d] = 1;
        m = 10 * m + d;
    }
    return m;
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to