标签:interview
19.4 Write a method which finds the maximum of two numbers. You should not use if-else or any other comparison operator.
int max(int a, int b) { int[] temp = {a, b}; // If a > b, (a - b) >> 31 will be 0...000000; // Else, it will be 11111111..1; // Thus, int k = ((a - b) >> 31) & 1; return temp[k]; }
CC150 19.4
原文地址:http://7371901.blog.51cto.com/7361901/1588281