public static String int2str(int x) {
if (x == 0) return "0";
StringBuilder res = new StringBuilder();
while (x > 0) {
res.insert(0, (char)('0' + x % 10));
x /= 10;
}
return res.toString();
}
Sigiloso
12 de fev. de 2011
Important to note that insertion at postion 0 everytime will require shifting of string and that will be O(n) for each insertion and o(n2) effectively.
Why not insert at end and after exiting loop reverse string. Both of these will be 0(n).