← Unit 4 · all exercises
Saved in this browser only

Is it in there

Return true when the target appears anywhere in the array. This is a linear search: you can stop as soon as you find it.

boolean contains(int[] values, int target)

Solution.java
Loading editor…
Results

Examples

  • Solution.contains(new int[]{1, 2, 3}, 2) → true
  • Solution.contains(new int[]{1, 2, 3}, 9) → false

There are also 3 hidden tests you can't see. Solve the problem, not the examples.