MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / searchInsert

Method searchInsert

src/com/blankj/easy/_0035/Solution.java:12–20  ·  view source on GitHub ↗
(int[] nums, int target)

Source from the content-addressed store, hash-verified

10 */
11public class Solution {
12 public int searchInsert(int[] nums, int target) {
13 int left = 0, right = nums.length - 1, mid = (right + left) >> 1;
14 while (left <= right) {
15 if (target <= nums[mid]) right = mid - 1;
16 else left = mid + 1;
17 mid = (right + left) >> 1;
18 }
19 return left;
20 }
21
22 public static void main(String[] args) {
23 Solution solution = new Solution();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected