Count Occurrences of Digit D

Given separate integers n and d, return the number of times digit d appears in n's ordinary decimal representation. Zero is represented by the single digit 0.

Given separate integers n and d, return the number of times digit d appears in n's ordinary decimal representation. Zero is represented by the single digit 0.

0 <= n <= 2,147,483,647 and 0 <= d <= 9. The ordinary decimal representation has no leading zeroes; zero is represented by one digit.

Example 1: input n = 10101, d = 0; output 2. Zero appears twice among the decimal digits.

Example 2: input n = 0, d = 0; output 1. Zero is represented by one zero digit.

Example 3: input n = 0, d = 4; output 0. The single zero digit does not match 4.

Category: Math & Numbers. Topic: math. Difficulty: Easy. Patterns: math.