60 lines
1.2 KiB
Python
60 lines
1.2 KiB
Python
from string import *
|
|
from re import *
|
|
from datetime import *
|
|
from collections import *
|
|
from heapq import *
|
|
from bisect import *
|
|
from copy import *
|
|
from math import *
|
|
from random import *
|
|
from statistics import *
|
|
from itertools import *
|
|
from functools import *
|
|
from operator import *
|
|
from io import *
|
|
from sys import *
|
|
from json import *
|
|
from builtins import *
|
|
import string
|
|
import re
|
|
import datetime
|
|
import collections
|
|
import heapq
|
|
import bisect
|
|
import copy
|
|
import math
|
|
import random
|
|
import statistics
|
|
import itertools
|
|
import functools
|
|
import operator
|
|
import io
|
|
import sys
|
|
import json
|
|
from typing import *
|
|
|
|
# @leet start
|
|
class Solution:
|
|
def search(self, nums: List[int], target: int) -> int:
|
|
|
|
def bin_search(low, high):
|
|
if low > high:
|
|
return -1
|
|
mid = (high + low) // 2
|
|
if nums[low] == target:
|
|
return low
|
|
if nums[high] == target:
|
|
return high
|
|
if nums[mid] == target:
|
|
return mid
|
|
if nums[mid] < target:
|
|
return bin_search(mid + 1, high)
|
|
if nums[mid] > target:
|
|
return bin_search(low, mid - 1)
|
|
|
|
return bin_search(0, len(nums) - 1)
|
|
|
|
|
|
|
|
# @leet end
|