When I do algorithm exercises, I found many people like to transfer a string to charArray before do operations?
I don't understand why do we bother do that? I mean, I can use string.charAt()
, why use string.toCharArray()
and then charArray[i]
? It's the same and even charArray
use O(n) memory.
Can anyone explain that to me?