<jupyter_start><jupyter_text>LeetCode 704. Binary Search Question    https://leetcode.com/problems/binary-search/    Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, then return its index, otherwise return -1.Example 1:    Input: nums = [-1,0,3,5,9,12], target = 9    Output: 4    Explanation: 9 exists in nums and its index is 4Example 2:    Input: nums = [-1,0,3,5,9,12], target = 2    Output: -1    Explanation: 2 does not exist in nums so return -1 Note:    You may assume that all elements in nums are unique.    n will be in the range [1, 10000].    The value of each element in nums will be in the range [-9999, 9999].  My Solution<jupyter_code>def search(num, t):
    for i in range(len(num)):
        if num[i] == t:
            return i  
    return -1
# test code
num = [-1,0,3,5,9,12]
t = 9
search(num, t)<jupyter_output><empty_output><jupyter_text>About My Solution    Binary Search를 쓰지 않고 순차적으로 탐색  My Result__Runtime__: 220 ms, faster than 84.81% of Python online submissions for Binary Search.__Memory Usage__: 12.6 MB, less than 98.69% of Python online submissions for Binary Search.  @cenkay's Solution<jupyter_code>def search(nums, target):
    l, r = 0, len(nums) - 1
    while l <= r:
        mid = (l + r) // 2
        if nums[mid] < target:
            l = mid + 1
        elif nums[mid] > target:
            r = mid - 1
        else:
            return mid
    return -1
# test code
nums = [-1,0,3,5,9,12]
target = 9
search(num, t)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10522999369880277, 'fraction_numerical': 0.04977945809703844, 'mean_word_length': 2.854368932038835, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '371030', 'license': 'MIT', 'n_tokens_mistral': 595, 'n_tokens_neox': 542, 'n_words': 208, 'path': 'LeetCode/LeetCode_704BinarySearch.ipynb', 'repo_name': 'foxsayy/python', 'size': '1587'}