bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1128. Number of Equivalent Domino Pairs

1128. Number of Equivalent Domino Pairs

Leetcode Solutions

Counting with a Hash Map

  1. Initialize an empty hash map counts to store the count of each unique domino identifier.
  2. Initialize pairsCount to 0, which will store the total number of equivalent domino pairs.
  3. Iterate through each domino in the dominoes list: a. Create a unique identifier for the domino by sorting its values and forming a tuple (min(domino[0], domino[1]), max(domino[0], domino[1])). b. If the identifier is already in the hash map, increment pairsCount by the current count of that identifier. c. Increment the count for the identifier in the hash map.
  4. Return pairsCount as the total number of equivalent domino pairs.
UML Thumbnail

Brute Force Comparison

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...