leetcode

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

commit f7d99782c47ebfb547844991de02651a8f586857
parent 53bd8eeb30e07ddb08936a041efce847d1851862
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu,  4 May 2023 15:29:35 +0200

Daily Problem

Diffstat:
AProblems/0649.cpp | 20++++++++++++++++++++
MREADME.md | 1+
2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/Problems/0649.cpp b/Problems/0649.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + string predictPartyVictory(string senate) { + queue<int> rq, dq; + int n = senate.size(); + + for (int i = 0; i < n; i++) (senate[i] == 'R' ? rq : dq).push(i); + + while (!rq.empty() && !dq.empty()) { + int a = rq.front(), b = dq.front(); + rq.pop(), dq.pop(); + if (a < b) + rq.push(a + n); + else + dq.push(b + n); + } + + return rq.size() ? "Radiant" : "Dire"; + } +}; diff --git a/README.md b/README.md @@ -307,6 +307,7 @@ for solving problems. | 0617 | Easy | [Merge Two Binary Trees](Problems/0617.cpp) | | 0621 | Medium | [Task Scheduler](Problems/0621.cpp) | | 0637 | Easy | [Average of Levels in Binary Tree](Problems/0637.cpp) | +| 0649 | Medium | [Dota2 Senate](Problems/0649.cpp) | | 0652 | Medium | [Find Duplicate Subtrees](Problems/0652.cpp) | | 0653 | Easy | [Two Sum IV - Input is a BST](Problems/0653.cpp) | | 0654 | Medium | [Maximum Binary Tree](Problems/0654.cpp) |