From 4f7f0b1f3499d055c1528175a74bb19ce978c8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Sat, 24 Jun 2023 18:45:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=AC=AC=E4=BA=8C=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 00-chartgpt/chainlit/nohup.out | 4 +++ .../day02/problem_solving_16.py" | 32 +++++++++++++++++++ .../day02/problem_solving_17.py" | 25 +++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 "14_\345\210\267\351\242\230/day02/problem_solving_16.py" create mode 100644 "14_\345\210\267\351\242\230/day02/problem_solving_17.py" diff --git a/00-chartgpt/chainlit/nohup.out b/00-chartgpt/chainlit/nohup.out index 50ee4a7..c0e57c1 100644 --- a/00-chartgpt/chainlit/nohup.out +++ b/00-chartgpt/chainlit/nohup.out @@ -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 diff --git "a/14_\345\210\267\351\242\230/day02/problem_solving_16.py" "b/14_\345\210\267\351\242\230/day02/problem_solving_16.py" new file mode 100644 index 0000000..9bebd00 --- /dev/null +++ "b/14_\345\210\267\351\242\230/day02/problem_solving_16.py" @@ -0,0 +1,32 @@ +""" +丢失的数字 +""" +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) diff --git "a/14_\345\210\267\351\242\230/day02/problem_solving_17.py" "b/14_\345\210\267\351\242\230/day02/problem_solving_17.py" new file mode 100644 index 0000000..d21da45 --- /dev/null +++ "b/14_\345\210\267\351\242\230/day02/problem_solving_17.py" @@ -0,0 +1,25 @@ +""" +移动零 +""" +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]) -- GitLab