Created
August 6, 2015 22:10
-
-
Save Maslor/b4f7e5bc745cd19636bf to your computer and use it in GitHub Desktop.
class that reverses a long string efficiently with StringBuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.StringBuilder; | |
public class ReverseLonger { | |
public static String shorterReverseLonger(String a, String b) { | |
if (a.length() < b.length()) { | |
return a + reverse(b) + a; | |
} else { | |
return b + reverse(a) + b; | |
} | |
} | |
public static String reverse(String str) { | |
String reverse = new StringBuilder(str).reverse().toString(); | |
return reverse; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment