求二叉排序树的最小根

来源:互联网 发布:网络 取代 书 编辑:程序博客网 时间:2024/05/29 08:32
public class Solve{ public static void main(String[] args){     int aa=minRoot(4,10,13);     int bb=minRoot(4,aa,15);     System.out.println(bb); }  public static int minRoot(int K,int a,int b){          if(a Math.pow(2, K) - 1 || b < 0)            return -1;        if (a >= Math.pow(2, K - 1) && b <= Math.pow(2, K - 1)) {            return (int) Math.pow(2, K - 1);        }        if (b > Math.pow(2, K - 1)) {            return (int)(Math.pow(2, K - 1)+minRoot(K-1,(int)(a-Math.pow(2, K - 1))                    ,(int)(b-Math.pow(2, K - 1))));        }        return minRoot(K-1,a,b);  }}

0 0
原创粉丝点击