clueless coding // TODO: be smarter

LeetCode Reverse String: Java Solution



TL;DR Code Solution


public String reverseString(String s) {

    char[] str = s.toCharArray();
    int length = s.length();

    for (int i = 0; i < length / 2; i++) {
        char temp = str[i];
        str[i] = str[length - i - 1];
        str[length - i - 1] = temp;
    }

    return new String(str);


}