0
下面的代碼塊的複雜性:轉換INT到串減少時間計算其長度
Scanner in=new Scanner(System.in);
int n=in.nextInt();
//converting the integer to string and calculating
//its length reduces the complexity
//to O(n) as compared to O(n^2)
String str=Integer.toString(n);
int length=str.length();length-=1;
我發現this code here。
我的問題是如何改變int爲字符串減少時間複雜性?
我投票關閉這一問題作爲題外話,因爲它要求通過互聯網上的一些隨機的人解釋不正確的陳述。 – Dukeling