(Java) Right or Wrong?

  • -1

    public class Solution {
    public int addDigits(int num) {
    int sum = 0;
    if (num == 0){
    return num;
    sum = sum + num%10;
    num = num/10;
    return sum;

    I know this is not an efficient answer, but it is also NOT correct? Site reported if input 10, output would also be 10, but I tried on my PC compiler, output is 1. What's wrong?

  • 1

    try input "78", the output should be 6 instead of 15.
    the sum should be a digit instead of an integer.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.