From b6f202332eb4d6b240d2d46bd70452dd52208ce8 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Sun, 17 Jul 2022 13:43:12 -0400 Subject: [PATCH] Time: 57 ms (34.64%), Space: 13.7 MB (15.83%) - LeetHub --- 38-count-and-say/38-count-and-say.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 38-count-and-say/38-count-and-say.py diff --git a/38-count-and-say/38-count-and-say.py b/38-count-and-say/38-count-and-say.py new file mode 100644 index 0000000..7d84701 --- /dev/null +++ b/38-count-and-say/38-count-and-say.py @@ -0,0 +1,24 @@ +class Solution(object): + def countAndSay(self, n): + """ + :type n: int + :rtype: str + """ + said = "1" + for i in range(2, n + 1): + counting = 0 + countedN = 0 + newSaid = "" + for a in range(len(said)): + if said[a] != counting: + if counting != 0: + newSaid += str(countedN) + str(counting) + counting = said[a] + countedN = 1 + else: + countedN += 1 + + newSaid += str(countedN) + str(counting) + said = newSaid + + return said \ No newline at end of file