Convert string to number & vice versa complexity

前端 未结 5 1897
梦如初夏
梦如初夏 2021-02-05 19:42

What would be the complexity of converting a string to its equivalent number or vice versa? Does it change depending on programming language?

On the face of it, one ne

5条回答
  •  伪装坚强ぢ
    2021-02-05 20:40

    If you're converting a number N to a string. It takes O(log(N)) with base 10. (If you divide by 10 and keep the remainder) If you're converting a string with length N, then it takes O(N). (If you use the algorithm whic keeps adding to your number 10^(N)*digit(N))

    If you use functions which are not yours (let's say for string), you can only expect them to be slower.

提交回复
热议问题