What is the fastest way to check for duplicate digits of a number?
问题 Let's say I want to check if a number n = 123 has duplicate digits. I tried: #include <iostream> using namespace std; int main() { int n = 123; int d1 = n % 10; int d2 = ( n / 10 ) % 10; int d3 = ( n / 100 ) % 10; if( d1 != d2 && d1 != d3 && d2 != d3 ) { cout << n << " does not have duplicate digits.\n"; } } Is there any faster solution to this problem? Update Sorry for being unclear. The code above was written in C++ only for description purpose. I have to solve this problem in TI-89, with a