Last active
February 8, 2021 11:58
-
-
Save sobrinho/ef61286c800b9070031c09214a91d4ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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