Two Sums

Write a method that takes an array of numbers. If a pair of numbers in the array sums to zero, return the positions of those two numbers. If no pair of numbers sums to zero, return ‘nil’.

Screen Shot 2016-08-12 at 2.32.27 PM

Takeaway: note how the second while loop is nested inside the first one.

Second time solving this:

screen-shot-2016-09-09-at-6-01-22-pm

Advertisements
Two Sums

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