fix:汇总区间

上级 63bb2706
......@@ -136,3 +136,7 @@ Traceback (most recent call last):
File "/Users/qinyingjie/miniconda3/envs/py36tf1/lib/python3.9/site-packages/openai/api_requestor.py", line 533, in request_raw
raise error.APIConnectionError(
openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='opencatgpt.openai.azure.com', port=443): Max retries exceeded with url: //openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-05-15 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x124281c40>: Failed to resolve 'opencatgpt.openai.azure.com' ([Errno 8] nodename nor servname provided, or not known)"))
2023-06-23 14:38:43 - WARNING! engine is not default parameter.
engine was transferred to model_kwargs.
Please confirm that engine is what you intended.
2023-06-23 14:38:43 - Your app is available at http://localhost:8000
"""
汇总区间
"""
from typing import List
def getRange(start, end):
if start == end:
return str(start)
else:
return str(start) + '->' + str(end)
class Solution:
def summaryRanges(self, nums: List[int]) -> List[str]:
"""
数组变量,差值不为1,则特殊处理
:param nums:
:return:
"""
if not nums:
return []
result = []
start = nums[0]
for i in range(1, len(nums)):
if nums[i] != nums[i - 1] + 1:
result.append(getRange(start, nums[i - 1]))
start = nums[i]
result.append(getRange(start, nums[-1]))
return result
if __name__ == '__main__':
root = Solution().summaryRanges([0, 1, 2, 4, 5, 7])
print(root)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册