Problem
Given a string word, write a function solution that returns the number of occurrences of a specific character c within the given string.
Constraints
wordconsists only of lowercase English letters.- The length of
wordis between 1 and 100 inclusive. cis a single lowercase English letter.
Test Case
| Test Case Number | word | c | return |
|---|---|---|---|
| 1 | "hello" | "l" | 2 |
| 2 | "algorithm" | "g" | 1 |
| 3 | "banana" | "a" | 3 |
Explanation for Test Case 1
- When
word = "hello"andc = "l", there are 2 occurrences of "l" in the string, so the return value is 2.
Explanation for Test Case 2
- When
word = "algorithm"andc = "g", there is 1 occurrence of "g" in the string, so the return value is 1.
Explanation for Test Case 3
- When
word = "banana"andc = "a", there are 3 occurrences of "a" in the string, so the return value is 3.