A to Z

Write a method that takes a string in and returns true if the letter “z” appears within three letters **after** an “a”. You may assume that the string contains only lowercase letters.

Thought Process:

string[idx] == a?
string[idx + 1] == z?
string[idx + 2] == z?
string[idx + 3] == z?

My answer:

Screen Shot 2016-08-12 at 11.42.43 AM

To simplify string [idx +n] == ” z”, write a while loop for idx2.

Provided solution:

Screen Shot 2016-08-11 at 8.53.02 PM

Advertisements
A to Z

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