leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0038.cpp (580B)
0 class Solution { 1 public: 2 string countAndSay(int n) { 3 string crnt = "1"; 4 for (int i = 1; i < n; i++) { 5 string res = ""; 6 int c = crnt.front(), count = 1; 7 for (int i = 1; i < crnt.size(); i++) { 8 if (crnt[i] == c) 9 count++; 10 else { 11 res += to_string(count) + (char)c; 12 count = 1; 13 c = crnt[i]; 14 } 15 } 16 crnt = res + to_string(count) + (char)c; 17 } 18 return crnt; 19 } 20 };