Given an array of integers and a target value, determine whether the target element exists in the array. Return true if the element is present, otherwise return false.
Example 1
Input: arr = [1,3,5,7,9], target = 5
Output: true
Explanation: The element 5 is present in the array, so the result is true.
Example 2
Input: arr = [2,4,6,8], target = 3
Output: false
Explanation: The element 3 does not exist in the array, so the result is false.
Example 3
Input: arr = [], target = 1
Output: false
Explanation: The array is empty, so no element exists.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
1 1
true
1 2 3 2
true
5 3 8 1 9 8
true