LetCode 38. 报数

xiaoxiao2021-02-28  29

static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }(); class Solution { public: string countAndSay(int n) { if (n == 1) { return "1"; } else { string output = countAndSay(n - 1), result = ""; int index = 0; while (index < output.length()) { char current = output[index]; int cursor = index, count = 0; while (cursor < output.length() && output[cursor] == current) { cursor++; count++; } char number = count + '0'; result += number; result += current; index += count; } return result; } } };
转载请注明原文地址: https://www.6miu.com/read-2100356.html

最新回复(0)