python实现 LeetCode36——Count and Say
2018-03-28 17:04
417 查看
count代表这个这个数一共有几个,利用count再加上这个位置的数,最终得到最后的结果
class Solution(object):
def countAndSay(self, n):
string='1'
while n>1:
string=self.countStr(string)
n=n-1
return string
def countStr(self,string):
result=''
count = 1
for i in range(len(string)):
if i<len(string)-1 and string[i]==string[i+1]:
count=count+1
else:
result=result+str(count)+string[i]
count = 1
return result
class Solution(object):
def countAndSay(self, n):
string='1'
while n>1:
string=self.countStr(string)
n=n-1
return string
def countStr(self,string):
result=''
count = 1
for i in range(len(string)):
if i<len(string)-1 and string[i]==string[i+1]:
count=count+1
else:
result=result+str(count)+string[i]
count = 1
return result
相关文章推荐
- leetcode:Count and Say【Python版】
- 【LeetCode with Python】 Count and Say
- [leetcode]Count and Say (伯爵说 C语言实现)
- 【LeetCode-面试算法经典-Java实现】【038-Count and Say(计数和表述)】
- 【Leetcode】【python】Count and Say
- [LeetCode]题解(python):038-Count and Say
- LeetCode 38 Count and Say(C,C++,Java,Python)
- 36_leetcode_Count and Say
- python实现 LeetCode36——Valid Sudoku
- LeetCode--Count and Say(Python)
- 【LeetCode 38】Count and Say(Python)
- LeetCode-38-Count and Say Python的int_to_string
- LeetCode--Count and Say(Python)
- Leetcode-Count and Say-Python
- leetcode 【 Two Sum 】python 实现
- [LeetCode]—Count and Say 读数字
- LeetCode 51. N-Queens--Python实现
- 【LeetCode】Count and Say
- LeetCode--Count Primes(素数个数)Python
- LeetCode 63. Unique Paths II--Python实现