@Test public void solutionRecursion() { assertNull(ReverseStringSolution.reverseStringRecursion(null)); assertEquals("", ReverseStringSolution.reverseStringRecursion("")); assertEquals("a", ReverseStringSolution.reverseStringRecursion("a")); assertEquals("olleh", ReverseStringSolution.reverseStringRecursion("hello")); assertEquals("!dlrow", ReverseStringSolution.reverseStringRecursion("world!")); long b = System.currentTimeMillis(); int count = SUPPRESS_TEST_LIMITATION; while (count > 0) { count--; ReverseStringSolution.reverseStringRecursion("yuzhouwan.com"); } long e = System.currentTimeMillis(); System.out.println(e - b); }
static String reverseStringRecursion(String s) { int length; if (s == null || (length = s.length()) <= 1) return s; String leftStr = s.substring(0, length / 2); String rightStr = s.substring(length / 2, length); return reverseStringRecursion(rightStr) + reverseStringRecursion(leftStr); }
ReverseStringSolution { static String reverseStringRecursion(String s) { int length; if (s == null || (length = s.length()) <= 1) return s; String leftStr = s.substring(0, length / 2); String rightStr = s.substring(length / 2, length); return reverseStringRecursion(rightStr) + reverseStringRecursion(leftStr); } }
ReverseStringSolution { static String reverseStringRecursion(String s) { int length; if (s == null || (length = s.length()) <= 1) return s; String leftStr = s.substring(0, length / 2); String rightStr = s.substring(length / 2, length); return reverseStringRecursion(rightStr) + reverseStringRecursion(leftStr); }  }
ReverseStringSolution { static String reverseStringRecursion(String s) { int length; if (s == null || (length = s.length()) <= 1) return s; String leftStr = s.substring(0, length / 2); String rightStr = s.substring(length / 2, length); return reverseStringRecursion(rightStr) + reverseStringRecursion(leftStr); }   }
ReverseStringSolution { static String reverseStringRecursion(String s) { int length; if (s == null || (length = s.length()) <= 1) return s; String leftStr = s.substring(0, length / 2); String rightStr = s.substring(length / 2, length); return reverseStringRecursion(rightStr) + reverseStringRecursion(leftStr); }    }