File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ # -*- coding: UTF-8 -*-
2+
3+ class Solution_31_40 :
4+ def countAndSay (self , n ):
5+ """
6+ :type n: int
7+ :rtype: str
8+ """
9+ curr = '1'
10+ for i in range (1 , n ):
11+ prev = curr
12+ curr = ''
13+ count = 1
14+ say = prev [0 ]
15+ for ch in prev [1 :]:
16+ if say == ch :
17+ count += 1
18+ else :
19+ curr += str (count ) + say
20+ say = ch
21+ count = 1
22+ curr += str (count ) + say
23+ return curr
Original file line number Diff line number Diff line change 1+ from unittest import TestCase
2+
3+ from solution_31_40 import Solution_31_40
4+
5+
6+ # -*- coding: UTF-8 -*-
7+ class TestSolution_31_40 (TestCase ):
8+ def setUp (self ):
9+ self .sln = Solution_31_40 ()
10+
11+ def test_countAndSay (self ):
12+ self .assertEqual (self .sln .countAndSay (2 ), '11' )
13+ self .assertEqual (self .sln .countAndSay (4 ), '1211' )
You can’t perform that action at this time.
0 commit comments