I need to make sure that a pair of numbers is either (1, 2) or (2, 1). Both x and y are always positive. The code I am using right now:
if ((x == 2 && y == 1) ||
(x == 1 && y == 2)) {
return 1;
}
It looks a little bulky, and I feel like it can be simplified. However, everything I tried resulted in false positives.
This is the most direct way to make this comparison.
It is also more readable than any alternative you may come up with, so no need to change it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With