Using recursion to find a character in a string

前端 未结 6 2094
囚心锁ツ
囚心锁ツ 2021-01-20 00:35

I am trying to find the first occurrence of a letter in a string. For example, p in apple should return 1. Here is what I have:

// Returns the index of the          


        
6条回答
  •  野的像风
    2021-01-20 01:33

    I'll give you some hints:

    1. When you've found the letter, you don't need to recurse further. Additionally, think about what you should be returning in this case.
    2. When do you recurse, also think about what the function should return.
    3. Is there anything special you need to do if the recursive call returns -1?

提交回复
热议问题