Leetcode-950 Reveal Cards In Increasing Order(按递增顺序显示卡牌)
1 class Solution 2 { 3 public: 4 vector<int> deckRevealedIncreasing(vector<int>& deck) 5 { 6 sort(deck.begin(),deck.end()); 7 vector<int> rnt (deck.size(),0); 8 int deckend = 0; 9 int flag = 1; 10 for(int i = 0;deckend < deck.size();i = (i+1)%(deck.size())) 11 { 12 if(!rnt[i]) 13 { 14 if(flag) rnt[i] = deck[deckend++]; 15 flag = !flag; 16 } 17 } 18 return rnt; 19 } 20 };
参考了大神的代码,本质是约瑟夫环。在还没填上数字的空格里隔一个填一个