fix:第二天

上级 13468770
......@@ -140,3 +140,7 @@ openai.error.APIConnectionError: Error communicating with OpenAI: HTTPSConnectio
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
2023-06-23 19:57:00 - WARNING! engine is not default parameter.
engine was transferred to model_kwargs.
Please confirm that engine is what you intended.
2023-06-23 19:57:00 - Your app is available at http://localhost:8000
"""
丢失的数字
"""
from typing import List
class Solution:
def missingNumber(self, nums: List[int]) -> int:
nums.sort()
if nums[0] != 0:
return 0
for i in range(1, len(nums)):
if nums[i] - nums[i - 1] > 1:
return nums[i] - 1
return nums[-1] + 1
def missingNumber2(self, nums: List[int]) -> int:
"""
主技巧 数学相关,求0到n的和
:param nums:
:return:
"""
total = len(nums) * (len(nums) + 1) / 2
sum_num = sum(nums)
return int(total - sum_num)
if __name__ == '__main__':
# root = Solution().missingNumber([3, 0, 1])
# root = Solution().missingNumber([0, 1])
root = Solution().missingNumber2([9, 6, 4, 2, 3, 5, 7, 0, 1])
print(root)
"""
移动零
"""
from typing import List
class Solution:
def moveZeroes(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
i = 0
j = 0
while j < len(nums):
if nums[j] != 0:
nums[i] = nums[j]
i += 1
j += 1
for index in range(i, len(nums)):
nums[index] = 0
print(nums)
if __name__ == '__main__':
Solution().moveZeroes([0, 1, 0, 3, 12])
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册