【翻唱】iToldUso -- 人质(张惠妹)# Music - 天籁之音
s*r
1 楼
Write a method which finds the maximum of two numbers. You should not
use if-else or any other comparison operator. pg 24
Example
input: 5, 10
output: 10
SOLUTION
Let A = 1st number & B= 2nd number
Step1. Perform operation C = (A-B).
Step2. k = Most significant bit of C , i.e k =1 if B>A else K=0
Step 3. return A - k*C. This will return the maximum of A and B.
题本身不难,不过我不理解,在step2,不用if-else怎么得到most significant bit啊
use if-else or any other comparison operator. pg 24
Example
input: 5, 10
output: 10
SOLUTION
Let A = 1st number & B= 2nd number
Step1. Perform operation C = (A-B).
Step2. k = Most significant bit of C , i.e k =1 if B>A else K=0
Step 3. return A - k*C. This will return the maximum of A and B.
题本身不难,不过我不理解,在step2,不用if-else怎么得到most significant bit啊