0

If there's any easy method to solve this problem pls let me know 🙂🙂🙏

https://code.sololearn.com/cuOYNw64t2Eo/?ref=app

24th Apr 2021, 1:51 PM
Shivam Shiva
Shivam Shiva - avatar
2 Respostas
+ 7
shivam Jaiswal , i habe my doubts about the last sample you mentioned: # N = 110 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + (1 + 0) + (1 + 1) + (1 + 2)+(1+3)+(1+4)+(1+5)+(1+6)+(1+7)+(1+8)+(1+9)+(1+10) = 110 to get the sum of digits from the number 20, you are using (1+10) which is 11, but the sum of the digit from 20 should be 2 (2 + 0) this is how this challenge is described on codewars website: * Find the sum of the digits of all the numbers from 1 to N (both ends included). So the solution is much more simple than the algorithm you used. in python it's just 6 lines of code with 2 nested for loops, or just one line with a list comprehension. java needs a bit more lines to realize that ;-)
24th Apr 2021, 5:19 PM
Lothar
Lothar - avatar
0
I don't got it. How can N(12) - > 51 and N(100) - > 46 be? Do you want to sum all digits for all numbers between 1 and 12, 1 and 100?
24th Apr 2021, 5:09 PM
Coding Cat
Coding Cat - avatar