package com.yan.leetcode;

import java.util.Arrays;

/**
 * Reverse String
 *
 * @author jingyangyan
 * @version 1.0
 * @create 2016-09-01 8:51
 */
public class ReverseString {
    public String reverseString(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = s.length() - 1; i >= 0; i--) {
            sb.append(s.charAt(i));
        }
        return sb.toString();
    }

    public String reverseString2(String s) {
        return new StringBuilder(s).reverse().toString();
    }

    public String reverseString3(String s) {
        char[] array = s.toCharArray();
        String reverse = "";  //注意这是空串，不是null
        for (int i = array.length - 1; i >= 0; i--)
            reverse += array[i];
        return reverse;
    }
}

@@ -389,32 +389,98 @@
 tring();%0A    %7D%0A%0A
+    /**%0A     * %E6%95%88%E7%8E%87%E6%AC%A1%E4%B9%8B%0A     *%0A     * @param s%0A     * @return%0A     */%0A
     public Strin
@@ -818,11 +818,405 @@
 e;%0A    %7D
+%0A%0A    /**%0A     * %E6%95%88%E7%8E%87%E6%9C%80%E9%AB%98%0A     *%0A     * @param s%0A     * @return%0A     */%0A    public String reverseString4(String s) %7B%0A        char%5B%5D chars = s.toCharArray();%0A        int i = 0, j = s.length() - 1;%0A        while (i %3C j) %7B%0A            char tmp = chars%5Bi%5D;%0A            chars%5Bi%5D = chars%5Bj%5D;%0A            chars%5Bj%5D = tmp;%0A            i++;%0A            j--;%0A        %7D%0A%0A        return new String(chars);%0A    %7D
 %0A%7D%0A

reverse string