Created
August 2, 2012 00:54
-
-
Save tylerkahn/3232056 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
def add1(arr, val, n) | |
if n.zero? | |
return arr.map! {|i| i == val ? i+1 : i } | |
else | |
arr.each_index do |j| | |
if arr[n < 0 ? -j - 1 : j] == val | |
arr[n < 0 ? -j - 1 : j] += 1 | |
n = n - (n < 0 ? -1 : 1) | |
return arr if n.zero? | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment