← Challenges

C: Binary Search

Write int solve(int *nums, int len, int target) that returns the index of target in the sorted array nums (which has len elements), or -1 if it is not present.

Examples

  • solve([1,3,5,7,9], 5, 5)2
  • solve([1,3,5,7,9], 5, 4)-1