About Python maximum recursion depth-998

Source: Internet
Author: User

Today, Leetcode, the Brute force solution 233
    • Problem:

Given an integer n, calculates the number of occurrences of the number 1 in all non-negative numbers less than or equal to N.

For example:

Given n = 13,

Returns 6 because the number 1 appears in the following number: 1,10,11,12,13.

    • Code:
classSolution:def __init__( Self): Self. Key= ' 1 '         Self. Result= 0    defCountdigitone ( Self, N):""": Type N:int: Rtype:int        """        ifN< 1:return  Self. Result Self. Result+= Str(n). Count ( Self. Key)ifN> 0: Self. Countdigitone (n-1)return  Self. Results=Solution ()Print(S.countdigitone (11221))
    • Error:

Maximum recursion depth exceeded while getting the STR in an object

    • Find Python maximum recursion depth
classSolution:def __init__( Self): Self. Key= ' 1 '         Self. Result= 0    defCountdigitone ( Self, N):""": Type N:int: Rtype:int        """        ifN< 1:return  Self. Result Self. Result+= Str(n). Count ( Self. Key)ifN> 0: Self. Countdigitone (n-1)return  Self. Results=Solution () forIinch Range(0,1000000):Print(i)Print(S.countdigitone (i))

Output 998, then error, maximum recursion depth found, or peace of mind with while bar ~

About Python maximum recursion depth-998

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.