Skip to content

Instantly share code, notes, and snippets.

@sobrinho
Last active February 8, 2021 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sobrinho/ef61286c800b9070031c09214a91d4ac to your computer and use it in GitHub Desktop.
Save sobrinho/ef61286c800b9070031c09214a91d4ac to your computer and use it in GitHub Desktop.
# See https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/submissions/
#
# @param {Integer[]} time
# @return {Integer}
def num_pairs_divisible_by60(time)
seen = Hash.new(0)
total = 0
time.each do |number|
number = number % 60
pair = (60 - number) % 60
total += seen[pair]
seen[number] += 1
end
total
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment