Created
March 30, 2015 23:58
-
-
Save jocelynzz/755c77edc9997a8bb5d4 to your computer and use it in GitHub Desktop.
CC
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
public class solution { | |
public void reverse(String s) { | |
int len = s.length(); //len = 5 | |
//abcde | |
//ebcda | |
//edcba | |
if (s > 0) { | |
for (int i = 0; i < len/2; i++ ) { | |
char temp = s.charAt(i); //i = 0 temp = a | |
int pos = len - i - 1; //pos = 4 | |
s.charAt(i) = s.charAt(pos); //a -> e | |
s.charAt(pos) = temp; // e -> a | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment