leetcode

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

commit 2075aa952f7ef9a00d49dabfc634d604380d5737
parent a4e4d22fff05316e4dd1eb0ab54f246c9d4780b2
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Tue,  2 Apr 2024 16:07:38 +0200

1 Random Problem

Diffstat:
AProblems/1007.cpp | 21+++++++++++++++++++++
MREADME.md | 3++-
2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/Problems/1007.cpp b/Problems/1007.cpp @@ -0,0 +1,21 @@ +class Solution { + public: + int minDominoRotations(const vector<int> &tops, const vector<int> &bottoms) { + const int n = size(tops); + int up[7] = {0}, down[7] = {0}, both[7] = {0}; + + for (int i = 0; i < n; i++) { + if (tops[i] == bottoms[i]) + both[tops[i]]++; + else + up[tops[i]]++, down[bottoms[i]]++; + } + + for (int i = 1; i <= 6; i++) { + if (up[i] + down[i] != n - both[i]) continue; + return min(up[i], down[i]); + } + + return -1; + } +}; diff --git a/README.md b/README.md @@ -589,6 +589,7 @@ for solving problems. | 1003 | Medium | [Check If Word Is Valid After Substitutions](Problems/1003.cpp) | | 1004 | Medium | [Max Consecutive Ones III](Problems/1004.cpp) | | 1006 | Medium | [Clumsy Factorial](Problems/1006.cpp) | +| 1007 | Medium | [Minimum Domino Rotations For Equal Row](Problems/1007.cpp) | | 1008 | Medium | [Construct Binary Search Tree from Preorder Traversal](Problems/1008.cpp) | | 1010 | Medium | [Pairs of Songs With Total Durations Divisible by 60](Problems/1010.cpp) | | 1011 | Medium | [Capacity To Ship Packages Within D Days](Problems/1011.cpp) | @@ -1053,6 +1054,7 @@ for solving problems. | 2328 | Hard | [Number of Increasing Paths in a Grid](Problems/2328.cpp) | | 2331 | Easy | [Evaluate Boolean Binary Tree](Problems/2331.cpp) | | 2336 | Medium | [Smallest Number in Infinite Set](Problems/2336.cpp) | +| 2342 | Medium | [Max Sum of a Pair With Equal Sum of Digits](Problems/2342.cpp) | | 2343 | Medium | [Query Kth Smallest Trimmed Number](Problems/2343.cpp) | | 2348 | Medium | [Number of Zero-Filled Subarrays](Problems/2348.cpp) | | 2352 | Medium | [Equal Row and Column Pairs](Problems/2352.cpp) | @@ -1183,4 +1185,3 @@ for solving problems. | 3039 | Medium | [Apply Operations to Make String Empty](Problems/3039.cpp) | | 3070 | Medium | [Count Submatrices with Top-Left Element and Sum Less Than k](Problems/3070.cpp) | | 3101 | Medium | [Count Alternating Subarrays](Problems/3101.cpp) | -| 2342 | Medium | [Max Sum of a Pair With Equal Sum of Digits](Problems/2342.cpp) |