my java 3ms solution


  • 0
    S

    public class Solution {
    public String reverseString(String s) {
    char[] charArray = s.toCharArray();
    int left = 0; int right = charArray.length -1;
    while(left < right) {
    swapChars(charArray, left, right);
    left++; right--;
    }
    return String.valueOf(charArray);
    }
    public void swapChars(char[] chararray, int i, int j) {
    char temp = chararray[i];
    chararray[i] = chararray[j];
    chararray[j] = temp;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.