Skip to content

Instantly share code, notes, and snippets.

@zh4ngx
Last active December 23, 2015 23:39
Show Gist options
  • Save zh4ngx/6711203 to your computer and use it in GitHub Desktop.
Save zh4ngx/6711203 to your computer and use it in GitHub Desktop.
Find missing number from array
def missing_number num_array:
n = num_array.length + 1
expected = n * (n + 1) / 2
actual = num_array.reduce :+
missing = expected - actual
return missing
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment