Skip to content

Instantly share code, notes, and snippets.

@jocelynzz
Created March 30, 2015 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jocelynzz/755c77edc9997a8bb5d4 to your computer and use it in GitHub Desktop.
Save jocelynzz/755c77edc9997a8bb5d4 to your computer and use it in GitHub Desktop.
CC
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