diff --git a/search/binary_search.cpp b/search/binary_search.cpp index ebe488e5658..9ae2634dc6d 100644 --- a/search/binary_search.cpp +++ b/search/binary_search.cpp @@ -59,6 +59,7 @@ namespace binary_search { * @returns @param int index of val in vector arr *******************************************************************************/ uint64_t binarySearch(std::vector arr, uint64_t val) { + if (arr.size() <= 1) return arr[0]; uint64_t low = 0; // set the lowest point of the vector. uint64_t high = arr.size() - 1; // set the highest point of the vector.