I am solving reverse string problem. I wonder why the helper function for swapping 2 char does not work in my code. But it works if I write the code for swapping inside the while loop.
class Solution {
public void reverseString(char[] s) {
int left = 0;
int right = s.length - 1;
while (left < right) {
swap(s[left], s[right]);
left++;
right--;
}
}
// not working as expected
public void swap(char a, char b) {
char temp = b;
b = a;
a = temp;
}
}