Created
April 23, 2015 02:19
-
-
Save rootid/cf1be3f5f38aa748dd49 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//StringBuilder vs String | |
//quadratic time | |
public static String reverse(String s) | |
{ | |
String rev = ""; | |
for (int i=s.length();i>=0;i--) { | |
rev += s[i]; | |
} | |
return rev; | |
} | |
//Linear time | |
public static String reverse(String s) | |
{ | |
StringBuilder rev = new StringBuilder (); | |
for (int i=s.length();i>=0;i--) { | |
rev.append(s[i]); | |
} | |
return rev; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment