Given a number, N. Find the sum of all the digits of N
 
Example 1:
Input:
N = 12
Output:
3
Explanation:
Sum of 12's digits:
1 + 2 = 3
Example 2:
Input:
N = 23
Output
5
Explanation:
Sum of 23's digits:
2 + 3 = 5
Your Task:
You don't need to read input or print anything. Your task is to complete the function sumOfDigits() which takes an integer N as input parameters and returns an integer, total sum of digits of N.
Expected Time Complexity: O(log_{10}N)
Expected Space Complexity: O(1)
 
Constraints:
1<=N<=10^{5}

Difficulty: EASY
Tags: Number theory
Expected Time Complexity: O(log_{10}N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3



class Solution:

    def sumOfDigits (self, N):

        # code here

Solutions:
class Solution:

	def sumOfDigits(self, N):
		sd = 0
		num = N
		while num > 0:
			ld = num % 10
			sd += ld
			num = num // 10
		return sd


class Solution:

	def sumOfDigits(self, n):
		s = 0
		while n > 0:
			r = n % 10
			s = s + r
			n = n // 10
		return s


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		for i in range(0, N):
			digit = N % 10
			sum = sum + digit
			N = N // 10
		return sum


class Solution:

	def sumOfDigits(self, N):
		if N < 10:
			return N
		return N % 10 + self.sumOfDigits(N // 10)


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		while N != 0:
			remainder = N % 10
			sum += remainder
			N //= 10
		return sum


class Solution:

	def sumOfDigits(self, N):
		n = str(N)
		sum = 0
		for i in n:
			sum += int(i)
		return sum


class Solution:

	def sumOfDigits(self, N):
		mylist = [int(x) for x in str(N)]
		return sum(mylist)


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		while N != 0:
			digit = N % 10
			sum += digit
			N = N // 10
		return sum


class Solution:

	def sumOfDigits(self, N):
		answer = 0
		string = str(N)
		for i in range(len(string)):
			answer += int(string[i])
		return answer


class Solution:

	def sumOfDigits(self, N):
		a = str(N)
		s = 0
		for i in a:
			s += int(i)
		return s


class Solution:

	def sumOfDigits(self, N):
		s = 0
		while N != 0:
			t = N % 10
			s = s + t
			N = N // 10
		return s


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		for digit in str(N):
			sum += int(digit)
		return sum


class Solution:

	def sumOfDigits(self, N):
		l = [int(i) for i in str(N)]
		return sum(l)


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		while N > 0:
			rem = N % 10
			sum = sum + rem
			N = N // 10
		return sum


class Solution:

	def sumOfDigits(self, N):
		summ = sum((int(digits) for digits in str(N)))
		return summ


class Solution:

	def sumOfDigits(self, N):
		summ = 0
		for i in str(N):
			summ += int(i)
		return summ


class Solution:

	def sumOfDigits(self, N):
		s = 0
		while N > 0:
			r = N % 10
			s += r
			N = N // 10
		return s


class Solution:

	def sumOfDigits(self, N):
		s = str(N)
		l = 0
		r = len(s) - 1
		ans = self.findsum(s, l, r)
		return ans

	def findsum(self, s, l, r):
		if l > r:
			return 0
		else:
			return int(s[l]) + self.findsum(s, l + 1, r)


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		while N != 0:
			sum += N % 10
			N = int(N / 10)
		return sum


class Solution:

	def sumOfDigits(self, N):
		sumi = 0
		while N != 0:
			sumi += N % 10
			N //= 10
		return sumi


class Solution:

	def sumOfDigits(self, n):
		sum = 0
		while n > 0:
			sum += int(n % 10)
			n = int(n / 10)
		return sum


class Solution:

	def sumOfDigits(self, n):
		sum = 0
		for c in str(n):
			sum += int(c)
		return sum


class Solution:

	def sumOfDigits(self, N):
		summ = 0
		while N >= 1:
			summ = summ + N % 10
			N = N // 10
		return summ


class Solution:

	def sumOfDigits(self, N):
		a = str(N)
		sum = 0
		for b in a:
			sum = sum + int(b)
		return sum


class Solution:

	def sumOfDigits(self, N):
		result = 0
		while N != 0:
			num = N % 10
			result += num
			N = N // 10
		return int(result)


class Solution:

	def sumOfDigits(self, N):
		d = [int(d) for d in str(N)]
		return sum(d)


class Solution:

	def sumOfDigits(self, n):
		sum = 0
		while n:
			l = n % 10
			sum += l
			n = n // 10
		return sum


class Solution:

	def sumOfDigits(self, N):
		n_str_list = list(str(N))
		acum = 0
		for x in n_str_list:
			acum += int(x)
		return acum


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		string = str(N)
		arr = map(int, string)
		res = list(arr)
		if len(res):
			for i in res:
				sum = sum + i
			return sum


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		while N > 0:
			mod = N % 10
			N = N // 10
			sum = sum + mod
		return sum


class Solution:

	def sumOfDigits(self, n):
		res = 0
		while n != 0:
			rem = n % 10
			res += rem
			n = n // 10
		return res


class Solution:

	def sumOfDigits(self, N):
		sum1 = 0
		temp = N
		while temp > 0:
			sum1 = sum1 + temp % 10
			temp = temp // 10
		return sum1


class Solution:

	def sumOfDigits(self, N):
		if N < 9:
			return N
		else:
			return N % 10 + self.sumOfDigits(N // 10)


class Solution:

	def sumOfDigits(self, N):
		var = str(N)
		var_len = int(len(var))
		total = 0
		for i in range(var_len):
			vars = int(var[i])
			total = total + vars
		return total


class Solution:

	def sumOfDigits(self, N):
		str1 = str(N)
		res = 0
		for i in range(0, len(str1)):
			val = N % 10
			res = res + val
			N = N // 10
		return res


class Solution:

	def sumOfDigits(self, N):
		SUM = 0
		while N > 0:
			SUM = SUM + N % 10
			N = N // 10
		return SUM


class Solution:

	def sumOfDigits(self, N):
		tot = 0
		while N > 0:
			dig = N % 10
			tot = tot + dig
			N = N // 10
		return tot


class Solution:

	def sumOfDigits(self, N):
		no = str(N)
		res = 0
		for i in no:
			res += int(i)
		return res


class Solution:

	def sumOfDigits(self, N):
		(temp, total) = (N, 0)
		while temp != 0:
			(total, temp) = (total + temp % 10, temp // 10)
		return total


class Solution:

	def sumOfDigits(self, N):
		numstr = str(N)
		digits = len(numstr)
		sum = 0
		for i in range(0, digits):
			tempnumstr = numstr[i]
			tempnum = int(tempnumstr)
			sum = sum + tempnum
		return sum


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		while N > 0:
			last = N % 10
			N = N // 10
			sum = sum + last
		return sum


class Solution:

	def sumOfDigits(self, N):
		count = 0
		while N >= 1:
			count += N % 10
			N = int(N / 10)
		return count


class Solution:

	def sumOfDigits(self, n):
		sum = 0
		while n != 0:
			digit = n % 10
			sum += digit
			n //= 10
		return sum


class Solution:

	def sumOfDigits(self, N):
		count = 0
		for num in str(N):
			count += int(num)
		return count


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		while N > 0:
			d = N % 10
			sum = sum + d
			N = N // 10
		return sum


class Solution:

	def sumOfDigits(self, N):
		s = str(N)
		sum = 0
		for i in range(len(s)):
			sum += int(s[i])
		return sum


class Solution:

	def sumOfDigits(self, N):
		sum = 0
		while N != 0:
			l = N % 10
			sum += l
			N = N // 10
		return sum


class Solution:

	def sumOfDigits(self, n):
		n = str(n)
		result = 0
		for i in n:
			result += int(i)
		return result


import math

class Solution:

	def sumOfDigits(self, N):
		if N < 0:
			return 1
		sum = 0
		while N > 0:
			q = math.floor(N % 10)
			sum = sum + q
			N = math.floor(N / 10)
		return math.floor(sum)


class Solution:

	def sumOfDigits(self, N):
		out = 0
		while N:
			a = N % 10
			out = out + a
			N = (N - a) / 10
		return int(out)


class Solution:

	def sumOfDigits(self, N):
		Count = 0
		while N > 0:
			r = N % 10
			Count = Count + r
			N = N // 10
		return Count


class Solution:

	def sumOfDigits(self, N):
		res = 0
		while N > 0:
			last = N % 10
			res += last
			N //= 10
		return res


class Solution:

	def sumOfDigits(self, N):
		s = 0
		while N != 0:
			a = N % 10
			s += a
			N = N // 10
		return s


class Solution:

	def sumOfDigits(self, N):
		ne_n = 0
		while N:
			b = N % 10
			ne_n += b
			N -= b
			N = N // 10
		return ne_n