<script> function m(num, list) { var low = 0; var height = list.length - 1; while (low <= height) { var midder = parseInt((low + height) / 2) if (num == list[midder]) { return midder; } else if (num > list[midder]) { low = midder + 1 } else { height = midder - 1 } } return -1; } var s = m(16, [1, 2, 3, 4, 5, 6, 7, 8,9,10,11,12, 13, 14, 15, 16]); console.log(s); </script>
标签:二分,16,list,height,查找,low,var,midder From: https://www.cnblogs.com/liu521125/p/17849015.html