1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
digit-count-in-range.py 617 Bytes
Copy Edit Raw Blame History
kamyu authored 6 years ago . Create digit-count-in-range.py
# Time: O(logn)
# Space: O(1)
class Solution(object):
def digitsCount(self, d, low, high):
"""
:type d: int
:type low: int
:type high: int
:rtype: int
"""
def digitsCount(n, k):
pivot, result = 1, 0
while n >= pivot:
result += (n//(10*pivot))*pivot + \
min(pivot, max(n%(10*pivot) - k*pivot + 1, 0))
if k == 0:
result -= pivot
pivot *= 10
return result+1
return digitsCount(high, d) - digitsCount(low-1, d)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search