Below code snippet for String reverse
private static String reverseString(String originalString){
char arr[]= originalString.toCharArray();
char temp;
for(int i= 0,j=arr.length-1;i<(arr.length/2);i++,j--){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
return new String(arr);
I saw a lot of discussion about time complexity for the aforementioned String reverse, where some mentioned complexity as O (n / 2) and some O (n).
I would like to understand which one will really be the right time complexity for the return line.
Any insight would be really helpful for understanding the confusion here.
source
share