目录

三个月算法进阶--day71

dp[i]代表以元素nums[i]为结尾的连续子数组的最大和

定义状态,抽象子问题,肢解大问题。

记录

leetcode剑指offer第43题[1~n整数中1出现的次数]

class Solution:
    def countDigitOne(self, n: int) -> int:
        digit, res = 1, 0
        high, cur, low = n // 10, n % 10, 0
        while high != 0 or cur != 0:
            if cur == 0: res += high * digit
            elif cur == 1: res += high * digit + low + 1
            else: res += (high + 1) * digit
            low += cur * digit
            cur = high % 10
            high //= 10
            digit *= 10
        return res