Explanation

571.Check if an Array Contains a Value

Easy
Given an array nums and a target, return true if the target appears anywhere in the array and false otherwise. This yes/no question is the simplest kind of search. The key idea is the early exitEarly ExitLeaving a loop (or function) as soon as the answer is known, instead of finishing all iterations.: as soon as a match appears, the answer is certain, but "not found" can only be decided after every element has been checked.

Example 1:

Input: nums = [6,2,9,4], target = 9

Output: true

Example 2:

Input: nums = [6,2,9,4], target = 5

Output: false

+ 5 hidden test cases run on Submit.

Constraints:

  • ●1 ≤ nums.length ≤ 1000
  • ●-1000000 ≤ nums[i], target ≤ 1000000

nums =

[6, 2, 9, 4]

target =

9