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