python取中位数 位运算
# print(result)
low = 0
high =10
mid1=low + ((high - low) >> 1)
mid2 = (low + high) >> 1
mid3 = (low+high)/2
print(mid1==mid2)
因为其他语言low+high有溢出的风险,所以最好统一使用 mid=low + (high - low) >> 1表示。
# print(result)
low = 0
high =10
mid1=low + ((high - low) >> 1)
mid2 = (low + high) >> 1
mid3 = (low+high)/2
print(mid1==mid2)
因为其他语言low+high有溢出的风险,所以最好统一使用 mid=low + (high - low) >> 1表示。