Лучше думать об этом с конца дела.Допустим, у вас есть 3 возможных совпадения.Вызовы должны выглядеть так:
countSubStringMatchRecursive(target, key)
(The find operation is not -1, so call again)
1 + countSubStringMatchRecursive(target, key)
(The find operation is not -1, so call again)
1 + countSubStringMatchRecursive(target, key)
In this end case, the find operation is -1, so this function returns a 0.
Return value at this level is now 1 + 0 = 1
Return value at this level is now 1 + 1 = 2
Return value at the topmost level is now 1 + 2 = 3
Итак, как вы можете видеть, вызов функции 1+ - это, в основном, способ отслеживать количество.