solution in Ruby


  • 0
    H
        if target < nums[0]
            return 0
        end
        
        if target > nums[nums.length-1]
            return nums.length
        end
        
        for i in 0...nums.length do
            if nums[i] == target
                return i
            end 
            if nums[i] < target && nums[i+1] > target
                return i+1
            end
        end
    end

Log in to reply
 

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