From fc7588f39008165f3044d42bcae9db773609c4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Sun, 2 Jul 2023 10:45:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=87=8D=E6=9E=84=202=20=E8=A1=8C=E4=BA=8C?= =?UTF-8?q?=E8=BF=9B=E5=88=B6=E7=9F=A9=E9=98=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day03/problem_solving_29.py" | 33 +++++++++++++++++++ .../day03/problem_solving_30.py" | 18 ++++++++++ .../problem_solving_01.py" | 15 +++++++++ 3 files changed, 66 insertions(+) create mode 100644 "14_\345\210\267\351\242\230/01-\346\225\260\347\273\204/day03/problem_solving_29.py" create mode 100644 "14_\345\210\267\351\242\230/01-\346\225\260\347\273\204/day03/problem_solving_30.py" create mode 100644 "14_\345\210\267\351\242\230/04-\347\237\251\351\230\265/problem_solving_01.py" diff --git "a/14_\345\210\267\351\242\230/01-\346\225\260\347\273\204/day03/problem_solving_29.py" "b/14_\345\210\267\351\242\230/01-\346\225\260\347\273\204/day03/problem_solving_29.py" new file mode 100644 index 0000000..c6659e3 --- /dev/null +++ "b/14_\345\210\267\351\242\230/01-\346\225\260\347\273\204/day03/problem_solving_29.py" @@ -0,0 +1,33 @@ +""" +相对名次 +""" +from typing import List + + +class Solution: + def findRelativeRanks(self, score: List[int]) -> List[str]: + """ + 列表排序,并倒序,使用字典存储起来,再一个一个的去找 + :param score: + :return: + """ + res = [] + dict1 = {} + new_nums = sorted(score, reverse=True) + for index, num in enumerate(new_nums): + dict1[num] = index + 1 + for s in score: + if dict1[s] == 1: + res.append('Gold Medal') + elif dict1[s] == 2: + res.append('Silver Medal') + elif dict1[s] == 3: + res.append('Bronze Medal') + else: + res.append(str(dict1[s])) + return res + + +if __name__ == '__main__': + result = Solution().findRelativeRanks([5, 4, 3, 2, 1]) + print(result) diff --git "a/14_\345\210\267\351\242\230/01-\346\225\260\347\273\204/day03/problem_solving_30.py" "b/14_\345\210\267\351\242\230/01-\346\225\260\347\273\204/day03/problem_solving_30.py" new file mode 100644 index 0000000..0d2184d --- /dev/null +++ "b/14_\345\210\267\351\242\230/01-\346\225\260\347\273\204/day03/problem_solving_30.py" @@ -0,0 +1,18 @@ +""" +数组拆分 +""" +from typing import List + + +class Solution: + def arrayPairSum(self, nums: List[int]) -> int: + sum = 0 + nums.sort() + for i in range(0, len(nums), 2): + sum += nums[i] + return sum + + +if __name__ == '__main__': + result = Solution().arrayPairSum([1, 4, 3, 2]) + print(result) diff --git "a/14_\345\210\267\351\242\230/04-\347\237\251\351\230\265/problem_solving_01.py" "b/14_\345\210\267\351\242\230/04-\347\237\251\351\230\265/problem_solving_01.py" new file mode 100644 index 0000000..48287fc --- /dev/null +++ "b/14_\345\210\267\351\242\230/04-\347\237\251\351\230\265/problem_solving_01.py" @@ -0,0 +1,15 @@ +""" +重构 2 行二进制矩阵 +""" +from typing import List + + +class Solution: + def reconstructMatrix(self, upper: int, lower: int, colsum: List[int]) -> List[List[int]]: + + pass + + +if __name__ == '__main__': + result = Solution().reconstructMatrix(2, 1, [1, 1, 1]) + print(result) -- GitLab