Digit Character to Integer

You are given a character ch representing a digit from '0' to '9'.

Your task is to convert this digit character into its corresponding integer value and return the result.

Example 1:

Input:

ch = '7'

Output:

7

Explanation:

The character '7' represents the digit seven. Converting it to an integer gives the value 7.

Example 2:

Input:

ch = '0'

Output:

0

Explanation:

The character '0' represents the digit zero. Its corresponding integer value is 0.

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • ch is a character between '0'and '9', inclusive.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
int digitToInteger(char ch) {
// Write your code here
}
};
Test Case

Input:

Ch