leetcode

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

0649.cpp (517B)


      1 class Solution {
      2   public:
      3     string predictPartyVictory(string senate) {
      4         queue<int> rq, dq;
      5         int n = senate.size();
      6 
      7         for (int i = 0; i < n; i++)
      8             (senate[i] == 'R' ? rq : dq).push(i);
      9 
     10         while (!rq.empty() && !dq.empty()) {
     11             int a = rq.front(), b = dq.front();
     12             rq.pop(), dq.pop();
     13             if (a < b)
     14                 rq.push(a + n);
     15             else
     16                 dq.push(b + n);
     17         }
     18 
     19         return rq.size() ? "Radiant" : "Dire";
     20     }
     21 };