Description
Write a function that takes a string as input and returns the string reversed.
Example: Given s = “hello”, return “olleh”.
public class Solution {
public String reverseString(String s) {
}
}
Solution
/**
* 344. Reverse String
*
* @author kimtaeng
* created on 2018. 1. 10.
*/
public class Solution {
public String reverseString(String s) {
char[] arr = s.toCharArray();
int inputLength = s.length();
for (int currentIndex = 0; currentIndex < inputLength / 2; currentIndex++) {
char temp = arr[currentIndex];
arr[currentIndex] = arr[inputLength - 1 - currentIndex];
arr[inputLength - 1 - currentIndex] = temp;
}
return String.valueOf(arr);
}
}