MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / exist

Method exist

src/class006/Code01_FindNumber.java:47–63  ·  view source on GitHub ↗
(int[] arr, int num)

Source from the content-addressed store, hash-verified

45
46 // 保证arr有序,才能用这个方法
47 public static boolean exist(int[] arr, int num) {
48 if (arr == null || arr.length == 0) {
49 return false;
50 }
51 int l = 0, r = arr.length - 1, m = 0;
52 while (l <= r) {
53 m = (l + r) / 2;
54 if (arr[m] == num) {
55 return true;
56 } else if (arr[m] > num) {
57 r = m - 1;
58 } else {
59 l = m + 1;
60 }
61 }
62 return false;
63 }
64
65}

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected