Implement upperBound utility
Java
Medium
5 views
Problem Description
Task: return first index where a[i] > target in sorted array.
Output Format
Return value
Constraints
Use binary search loop.
Official Solution
static int upperBound(int[] a,int target){int l=0,r=a.length;while(l<r){int m=l+(r-l)/2; if(a[m]>target) r=m; else l=m+1;}return l;}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!