Reversed String

Write a method that will take a string as input, and return a new string with the same letters in reverse order.  Don’t use String’s reverse method; that would be too simple.

Thought process:

0 1 2 3
a b c d => dcba

“a”  => string[0] + “”
“ba” => string[1] + a
“cba” => string[2] + ba
“dcba” => string[3] + cba

new reversed string = string[i] + previously reversed string

Solution:

Screen Shot 2016-08-11 at 2.24.38 PM

 

Advertisements
Reversed String

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s