Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
Subscribe to see which companies asked this question.
Java Code:
public class Solution {
public String reverseString(String s) {
char[] sc = s.toCharArray();
int lsd = 0;
int rsd = sc.length - 1;
while (lsd < rsd) {
char c = sc[lsd];
sc[lsd] = sc[rsd];
sc[rsd] = c;
lsd++;
rsd--;
}
return new String(sc);
}
}