4 lines python solution (beats 93%)


  • -2
    X
    class Solution(object):
        def search(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: bool
            """
            if target in nums:
                return True
            else:
                return False
    

  • 1
    L

    This is O(n), not O(lgn), and it can be simplified to one line.

    class Solution(object):
        def search(self, nums, target):
            """
            :type nums: List[int]
            :type target: int
            :rtype: bool
            """
            return target in nums
    

Log in to reply
 

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