【LeetCode】【字符串】题号:*151. 翻转字符串里的单词
作者:互联网
every blog every motto: You will never know unless you try
0. 前言
生活好难,再坚持坚持!
1. 字符串
1.1 题目
1.2
class Solution:
def optimalDivision(self, nums: List[int]) -> str:
lens = len(nums)
if lens == 0:
return ''
elif lens == 1:
return str(nums[0])
elif lens == 2:
return str(nums[0]) + '/' + str(nums[1])
# 第一个值
result = str(nums[0]) + '/('
# 中间值
for i in range(1, lens - 1):
result += str(nums[i]) + '/'
# 最后一个值
result += str(nums[-1]) + ')'
return result
1.3
标签:151,return,nums,lens,result,str,字符串,题号 来源: https://blog.csdn.net/weixin_39190382/article/details/119393577