AscalifyCodeLibs
Back to DSADSA → SearchingQuestion 1 of 4
Linear Search
Searching
Linear search: print the 0-based index of `target` in `nums`, or `-1` if not found.
Example 1:
Input: nums = [1,3,5,7,9], target = 7
Output: 3
Explanation: 7 is found at index 3.
Example 2:
Input: nums = [1,3,5,7,9], target = 2
Output: -1
Example 3:
Input: nums = [10], target = 10
Output: 0
Code
Testcase / Output
Default testcase
target = 7, nums = [1, 3, 5, 7, 9]
Expected output
3
Returned results
Click Run to execute your code against the testcase.