python

Add digits until the result has only one digit  #angularjs #reactjs

  • as far as the error message is concerned, if addDigits is a class method, then you need to replace addDigits(self,num) with
  • You should call self.addDigits instead of just addDigits , since it’s class’ method.
  • Because standalone function addDigits is not defined, only as a method of an object which is available inside the method itself as self (the first argument)
  • Sign up or log in to customize your list.
  • Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

Second, I can’t print this return value on my local. it gives me a “None”. could any one help me to explain where is wrong in my code? thanks!

@ng_real_ninja: Add digits until the result has only one digit #angularjs #reactjs

I have two questions here. First, leetcode web gives me this error

Second, I can’t print this return value on my local. it gives me a

, since it’s class’ method. Because this is recursion, your method returns something only from the last method call, but not from any previous call. it should look something like this:

python

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.