We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
649. Dota2 Senate
思维题+模拟题。
好久不见的队列题。贪心思想,每个人肯定尽量ban在自己后面的不同阵营的人。所以用队列存储,每次用完后对优先级i+n。
i+n
class Solution { public String predictPartyVictory(String senate) { Queue<Integer> q1 = new LinkedList<>(), q2 = new LinkedList<>(); int n = senate.length(); for(int i = 0; i < n; i++){ if (senate.charAt(i) == 'R') { q1.add(i); } else { q2.add(i); } } while(!q1.isEmpty() && !q2.isEmpty()){ int r_index = q1.poll(), d_index = q2.poll(); if(r_index < d_index) q1.add(r_index + n); else q2.add(d_index + n); } return (q1.size() > q2.size())? "Radiant" : "Dire"; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
649. Dota2 Senate
649. Dota2 Senate
思维题+模拟题。
好久不见的队列题。贪心思想,每个人肯定尽量ban在自己后面的不同阵营的人。所以用队列存储,每次用完后对优先级
i+n
。The text was updated successfully, but these errors were encountered: