Write a function that takes a string as input and returns the string reversed.

Example:
Given s = “hello”, return “olleh”.

1
2
3
4
5
6
7
8
9
10
11
12
public class Solution {
public String reverseString(String s) {
if (s == null) return null;
StringBuilder sb = new StringBuilder();

for (int i = s.length() - 1; i >= 0; i--) {
sb.append(s.charAt(i));
}

return sb.toString();
}
}