---
title: "Discussion on \"Count Number of Digits\" | Hashnode"
description: "Discussion on \"Count Number of Digits\". Naive:\nTime Complexity: O(log₁₀(n))\nSpace Complexity: O(1)\ndef countDigits(n:int) -> int:\n    int res = 0\n    while (x>0):\n        x = x//10\n        res += 1\n    return res\n\nRecursive Way:\nTime Complexity: O(log₁₀(n))\nSpace Complexity: O(log₁₀(n))\nde..."
url: "https://hashnode.com/posts/count-number-of-digits/67eb3daad41ded62923c7af3"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Count Number of Digits](https://dstruct.hashnode.dev/count-number-of-digits?utm_source=hashnode&utm_medium=feed)

Naive: Time Complexity: O(log₁₀(n)) Space Complexity: O(1) def countDigits(n:int) -> int: int res = 0 while (x>0): x = x//10 res += 1 return res Recursive Way: Time Complexity: O(log₁₀(n)) Space Complexity: O(log₁₀(n)) de...

Apr 1, 2025 · 1 min read · dstruct.hashnode.dev  
Read the article

-   [#python](https://hashnode.com/tag/python)
-   [#maths](https://hashnode.com/tag/maths)
-   [#dsa](https://hashnode.com/tag/dsa)

## Written by

[Divyesh Vishwakarma](https://hashnode.com/@motidivya)

@motidivya · koparkhairane

  
[View profile](https://hashnode.com/@motidivya)

4k | 5⭐Hackerrank | Full Stack Web Developer | Competetive Programmer | Software Developer at Zeus Learning | MotiDivya

Extremely enthusiastic in the field of software and web development, Divyesh is continuously learning and gathering knowledge to remain abreast. Solving problems using Python(3) is intriguing for him so it's his niche currently working in Zeus Learning | MotiDivya

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
