fast check if the difference between two int32_t is 1 or 0
A straight forward way would be uint32_t diff = abs(num1 - num2); bool isZeroOrOne = (diff == 0 || diff == 1); or to simply check for all possible cases: int32_t diff = num1 - num2; bool isZeroOrOne = (diff == 0 || diff == 1 || diff == -1); Is there a more optimized way?
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.