If I have five variables
int a,b,c,d,e;
What is the most efficient way to make sure they are all unique?
if(a!=b && a!=c && a!=d && a!=e && b!=c && b!=d && b!=e && c!=d && c!=e && d!=e)
{
//Is this the most efficient way??
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That pretty much is the most efficient way. It’s not necessarily the best looking code I’ve seen but it’ll work just fine. Any other solution involving data structures or functions is unlikely to be faster.
I’d recode it for beauty though:
Not necessarily exactly like that, just something a bit easier on the eyes when reading.