Integer.parseInt()和Integer.toString()运行时 [英] Integer.parseInt() and Integer.toString() runtime

查看:83
本文介绍了Integer.parseInt()和Integer.toString()运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Integer.parseInt(String i)和Integer.toString(int i)的运行时间是否都为O(n)?

Would the runtime of Integer.parseInt(String i) and Integer.toString(int i) both be O(n)?

推荐答案

是的 Integer.parseInt("1000") Integer.toString(1000)具有时间复杂度 O(N)

Yes both of them Integer.parseInt("1000") and Integer.toString(1000) have time complexity O(N)

  • Integer.parseInt("1000")的内部代码在while循环中按字符和隐藏键将字符串读取为char

  • The internal code of Integer.parseInt("1000") reads the the strings char by char and covert to decimal in while loop

Integer.toString(1000)的内部代码读取整数并将每个数字转换为char并存储在 byte [] buf 中,然后创建新字符串从字节数组中

The internal code of Integer.toString(1000) reads the integers and convert every digit to char and stores in byte[] buf then creates new string from the byte array

这是

这篇关于Integer.parseInt()和Integer.toString()运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆