You are looking for the mode $r^\prime$. The hypergeometric
distribution is unimodal, in the sense that the most likely
values cluster together, in such a way that the two most
likely values are adjacent. That is why this method works.
For example, consider a hypergeometric distribution based on
an urn with 10 red balls and 10 green balls, from which you
sample 5 balls at random without replacement. Rounded to
four places, the probability of getting $X = k$ red balls is:
k : 0 1 2 3 4 5
h(k): 0.0163 0.1354 0.3483 0.3483 0.1354 0.0163
In this case, two adjacent values $k= 2$ and $3$ are tied for 'most likely', with probability 0.3483.
Using the hypergeometric formula (with parameters 10, 10, and 5), if you set $h(k) = h(k-1)$
and solve for $k,$ you will get the integer value $k = 3$.
In other examples, you might not get an integer value, but
the value will be within 1 of the mode. This will be true whether
there is a 'double-mode' as in my example, or a single most likely
value of $k$.
You might want to try it for an urn with 5 red balls and 3 black ones, from which you draw 5 balls. In this case, integer
$k = 3$ is a unique mode. What noninteger value near 3 do you
get when you solve the equation? (Express $h(\cdot)$ in terms
of factorials; there is a lot of cancelling.)
k : 0 1 2 3 4 5
h(k): 0.0000 0.0000 0.1786 0.5357 0.2679 0.0179
You might want to look at the Wikipedia article on 'hypergeometric distribution; which has a formula for the mode in terms of the
total number of balls in the urn, the number of red balls, and
the number being sampled.