二分查找,求mid值的类型溢出问题

  1. int l = Int32.MaxValue;//2147483647
  2. int r = Int32.MaxValue;//2147483647
  3. Console.WriteLine((l + r)/2);//-1
  4. Console.WriteLine(l + (r - l) / 2);//2147483647




原文地址:https://www.cnblogs.com/xiejunzhao/p/50e7d0bf713488b92e4379187576454b.html