log(n) solution


  • 0
    X

    class Solution {
    public boolean search(int[] nums, int target) {
    if(null == nums || nums.length == 0) return false;
    return sear(nums, target, 0, nums.length - 1);
    }

    public boolean sear(int[] nums,int target,int low,int high){
    	boolean exist = false;
    	
    	if(low <= high){
    		int mid = (low + high)/2;
        	
        	if(nums[mid] == target) exist = true;
        	else exist = sear(nums, target, low, mid-1) || sear(nums, target, mid+1, high);
    	}
    	
    	return exist;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.