public static int binarySearch(int[] nums, int target) {
        //write your code here
        int[]A=nums;
        int t=target, n=A.length;
        int l=0, r=n-1;
        while (l<=r) {
            int m=l+(r-l)/2;
            if (A[m]==t) {
                if (m==0||A[m-1]!=A[m])
                    return m;
                else r=m-1;
            } else if(A[m]<t) {
                l=m+1;
            } else {
                r=m-1;
            }
        }
        return -1;
    }