算法與數據結構(14)—— 二分查找變種(ceil與floor)

當存在大量重複的元素時,floor找的是第一個,ceil找的是第一個。 當不存在指定的元素時,floor是比其小最大的一個,而ceil是比其大最小的一個。 static int floor(Comparable[] arr, Comparable target){ // 尋找比target小的最大索引 int l = -1, r = arr.length-1;
相關文章
相關標籤/搜索