提交 fc7588f3 编写于 作者: 檀越@新空间's avatar 檀越@新空间 🐭

fix:重构 2 行二进制矩阵

上级 a6ad594e
"""
相对名次
"""
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)
"""
数组拆分
"""
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)
"""
重构 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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册