leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit 137b128c4eee4ec8ec4fd2af216f4924d0789c48
parent 6919fb5e22d4a209a865b67c021d8a90497fd499
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Mon, 16 Oct 2023 20:44:43 +0000

A Random Problem

Diffstat:
AProblems/1726.cpp | 14++++++++++++++
MREADME.md | 1+
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/Problems/1726.cpp b/Problems/1726.cpp @@ -0,0 +1,14 @@ +class Solution { + public: + int tupleSameProduct(const vector<int> &nums) const { + unordered_map<int, int> um; + int res = 0; + for (int i = 0; i < nums.size(); i++) { + for (int j = i + 1; j < nums.size(); j++) { + const int prod = nums[i] * nums[j]; + res += 8 * um[prod]++; + } + } + return res; + } +}; diff --git a/README.md b/README.md @@ -693,6 +693,7 @@ for solving problems. | 1706 | Medium | [Where Will the Ball Fall](Problems/1706.cpp) | | 1721 | Medium | [Swapping Nodes in a Linked List](Problems/1721.cpp) | | 1722 | Medium | [Minimize Hamming Distance After Swap Operations](Problems/1722.cpp) | +| 1726 | Medium | [Tuple with Same Product](Problems/1726.cpp) | | 1727 | Medium | [Largest Submatrix With Rearrangements](Problems/1727.cpp) | | 1732 | Easy | [Find the Highest Altitude](Problems/1732.cpp) | | 1734 | Medium | [Decode XORed Permutation](Problems/1734.cpp) |