Last active
August 13, 2019 14:22
-
-
Save IlyaDonskikh/54ed3e0945ac190eade28a77a7c0fcfb to your computer and use it in GitHub Desktop.
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
arr = [2, 4, 5, 5, 8, 9, 11, 13] | |
t = 14 | |
min_index = 0 | |
max_index = arr.length - 1 | |
success = false | |
while (min_index != max_index) && !success do | |
sum = arr[min_index] + arr[max_index] | |
if sum > t | |
max_index -= 1 | |
elsif sum < t | |
min_index += 1 | |
else | |
success = true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment