class Solution {
    public String predictPartyVictory(String senate) {
        Queue<Integer> radiant = new LinkedList<>();
        Queue<Integer> dire = new LinkedList<>();
        for (int i = 0; i < senate.length(); i++) {
            (senate.charAt(i) == 'R' ? radiant : dire).offer(i);
        }
        
        while (!radiant.isEmpty() && !dire.isEmpty()) {
            int rIndex = radiant.poll();
            int dIndex = dire.poll();
            if (rIndex < dIndex) {
                radiant.offer(rIndex + senate.length());
            } else {
                dire.offer(dIndex + senate.length());
            }
        }
        
        return radiant.size() > dire.size() ? "Radiant" : "Dire";
    }

}

 

posted on 2017-08-25 08:16  keepshuatishuati  阅读(164)  评论(0编辑  收藏  举报