Skip to content

Instantly share code, notes, and snippets.

@zamar-roura
zamar-roura / cassidoo-259.py
Last active August 1, 2022 19:34
Given an integer n, count the total number of 1 digits appearing in all non-negative integers less than or equal to n.
import math
"""
Dirty and quick way with strings
"""
def numberOfOnesDirty(n):
sum = 0
for i in range(n+1):
sum += str(i).count('1')