题解 | #整数中1出现的次数(从1到n整数中1出现的次数)

整数中1出现的次数(从1到n整数中1出现的次数)

https://www.nowcoder.com/practice/bd7f978302044eee894445e244c7eee6

class Solution:
    def NumberOf1Between1AndN_Solution(self , n: int) -> int:
        
        # write code here
        count = 0
        for i in range(1,n+1):
            count_1 = str(i).count('1')
            count = count + count_1
        return count


全部评论

相关推荐

某物流公司 软件开发岗 总包26-30
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务