I am trying a leetcode question on reversing the string. I don't understand why my solution is not working. Can anyone code review it please?
class Solution {
public char[] reverseString(char[] s) {
char[] temp = new char[s.length];
int index = s.length - 1;
for (int i = 0; i < s.length; ++i){
temp[i] = s[index--];
}
return temp;
}
}
Leetcode says my output is ["h", "e", "l", "l", "o"] when the output should be ["o", "l", "l", "e", "h"]. Thanks for the help.