MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/add digits/solution.cpp:1–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2public:
3 int addDigits(int num) {
4//If number is 0 return 0
5 if(num==0)
6 {
7 return 0;
8 }
9//if the number is single digit return the number itself
10 if(num>0&&num<=9)
11 {
12 return num;
13 }
14//if number is divisible by 9 then by the divisibility test that a number divided by 9 has
15//the sum of digits as 9 return 9
16
17 if(num%9==0)
18 {
19 return 9;
20 }
21//else return the remainder on dividing by 9.
22 return num%9;
23 }
24};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected