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 0000000000000000000000000000000000000000..c6659e35a444db9e12385471e09ae2c83da87b34 --- /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 0000000000000000000000000000000000000000..0d2184da14fdc0c76a985e0f2aa4fa7ade39c179 --- /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 0000000000000000000000000000000000000000..48287fcae1b97324a624843a4ffd8c1c7973226f --- /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)