zoukankan      html  css  js  c++  java
  • Java UpperBound

    Java UpperBound

    /**
     * <html>
     * <body>
     *  <P> Copyright 1994-2018 JasonInternational </p>
     *  <p> All rights reserved.</p>
     *  <p> Created on 2018年4月10日 上午9:46:32</p>
     *  <p> Created by Jason</p>
     *  </body>
     * </html>
     */
    package cn.ucaner.algorithm.search;
    
    /**
     * Upper bound search algorithm.<br>
     * Upper bound is kind of binary search algorithm but:<br>
     * -It returns index of first element which is grater than searched value.<br>
     * -If searched element is bigger than any array element function returns first index after last element.<br>
     * <br>
     * Behaviour for unsorted arrays is unspecified.
     * <p>
     * Complexity O(log n).
     * <br>
     * @author Bartlomiej Drozd <mail@bartlomiejdrozd.pl>
     * @author Justin Wetherell <phishman3579@gmail.com>
     */
    public class UpperBound {
    
        private UpperBound() { }
    
        public static int upperBound(int[] array, int length, int value) {
            int low = 0;
            int high = length;
            while (low < high) {
                final int mid = (low + high) / 2;
                if (value >= array[mid]) {
                    low = mid + 1;
                } else {
                    high = mid;
                }
            }
            return low;
        }
    }
    

      

  • 相关阅读:
    思维导图github地址
    python操作mongodb根据_id查询数据的实现方法
    如何让nginx显示文件夹目录
    Scrapy爬虫返回302重定向问题解决方法
    K8s
    Dockerfile文件详解
    k8s简介
    mongodb存储过程
    存储过程详解
    Docker 镜像加速
  • 原文地址:https://www.cnblogs.com/jasonandy/p/9243251.html
Copyright © 2011-2022 走看看