889. Check if a Large Number is Divisible by 9

You are given a string s representing a large non-negative integer. Your task is to determine whether this number is divisible by 9 or not.

Due to the large size of the number, you cannot store it in standard numeric data types like int, long, or long long. You must process it as a string.

A number is divisible by 9 if and only if the sum of its digits is divisible by 9.

Example 1:

Input: s = "69354"

Output: Yes

Explanation: 6+9+3+5+4 = 27, which is divisible by 9.

Example 2:

Input: s = "234567876799333"

Output: No

Explanation: The sum of the digits is not divisible by 9.

Now Your Turn!

Pick the correct output for the given input

Input: s = "3635883959606670431112222"

Still unsure what the problem is asking ?

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

Constraints:

  • 1 <= s.length <= 106
  • s contains only digits ('0' to '9')
  • The number will not have leading zeros unless it is "0" itself
0
class Solution {
public:
bool isDivisibleBy9(const string& s) {
// Your code goes here
}
};
Test Case

Input:

S