ReverseStringSolution { static String reverseStringLitterSpace(String s) { int len; if (s == null || (len = s.length()) <= 1) { return s; } char[] chars = new char[len]; s.getChars(0, len, chars, 0); char c; for (int i = 0; i < len / 2; i++) { c = chars[i]; chars[i] = chars[len - i - 1]; chars[len - i - 1] = c; } return new String(chars); }    }
@Test public void solutionLitterSpace() { assertNull(ReverseStringSolution.reverseStringLitterSpace(null)); assertEquals("", ReverseStringSolution.reverseStringLitterSpace("")); assertEquals("a", ReverseStringSolution.reverseStringLitterSpace("a")); assertEquals("olleh", ReverseStringSolution.reverseStringLitterSpace("hello")); assertEquals("!dlrow", ReverseStringSolution.reverseStringLitterSpace("world!")); long b = System.currentTimeMillis(); int count = SUPPRESS_TEST_LIMITATION; while (count > 0) { count--; ReverseStringSolution.reverseStringLitterSpace("yuzhouwan.com"); } long e = System.currentTimeMillis(); System.out.println(e - b); }