标签:ring cal string solution str == pre 开始 nbsp
1 //1与2交替出现,从下标2开始 2 class Solution 3 { 4 public: 5 int magicalString(int n) 6 { 7 string s = "122"; 8 for(int i = 2,k = 1;i < n;i ++,k = 3 - k) 9 { 10 for(int j = 0;j < s[i] - ‘0‘;j ++) s += to_string(k); 11 } 12 int res = 0; 13 for(int i = 0;i < n;i ++) res += s[i] == ‘1‘; 14 return res; 15 } 16 };
标签:ring cal string solution str == pre 开始 nbsp
原文地址:https://www.cnblogs.com/yuhong1103/p/12730344.html