We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1f48039 commit 9100078Copy full SHA for 9100078
src/Searches/BinarySearch.sol
@@ -36,15 +36,19 @@ contract BinarySearch {
36
uint256 currentElement = _nums[middle];
37
if (currentElement < value) {
38
minimum = middle + 1;
39
- } else if (currentElement > value) {
40
- maximum = middle - 1;
+ }
+ else if (currentElement > value) {
41
+ if (middle == 0) {
42
+ maximum = 0;
43
+ } else {
44
+ maximum = middle - 1;
45
46
} else {
- result = middle;
47
+ result = int256(middle);
48
// return the index position of the value in the array
49
return result;
50
}
51
- // return 0 if value is not in the array
- return 0;
52
+ return -1;
53
54
0 commit comments