[OTHER] Make BoyerMoore.findmajor
return java.util.Optional<Integer>
#4949
Labels
BoyerMoore.findmajor
return java.util.Optional<Integer>
#4949
What would you like to share?
Current implementation of
BoyerMoore.findmajor
returns-1
in case when there is no majority element. This is confusing, since the input array could contain-1
. I suggest to change this method to returnjava.util.Optional<Integer>
.Additional information
Solving this is a goof opportunity to clean up the existing code, I would suggest to introduce new private methods like
findCandidate
,calculateOccurrences
andisMajority
.The text was updated successfully, but these errors were encountered: