Skip to content

Instantly share code, notes, and snippets.

@sobrinho
Last active February 8, 2021 11:58
Embed
What would you like to do?
# 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