求二叉排序树的最小根

    xiaoxiao2021-04-18  52

    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 < b ){ int tmp = a ; a = b ; b = tmp ; } 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 ); } }
    转载请注明原文地址: https://ju.6miu.com/read-674794.html

    最新回复(0)