344. Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "Hello", Return "Olleh".
I wrote a code at the beginning.
class Solution { public String reversestring (string s) { int len = s.length ( ); String ans= ""; for (int i=len-1;i>=0;i--) ans+ =S.charat (i) ; return ans; }}
The last case of the above code did not pass, check the next found that the last cases about more than 42,300 characters
Because I beginner Java, for many details are not very understanding, then looked up some information, and also did some tests, found that compared to StringBuilder
Stitching at 50,000-character levels differs by more than 1600 times in speed. Here is to remind everyone string when using a large number of splicing, as far as possible to replace StringBuilder
[JAVA] String splicing Efficiency