Re: [閒聊] 每日leetcode
原來python的compare function要回傳數值不是bool==
搞了我好久
def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]:
m = {}
for i in range(10):
m[str(i)] = str(mapping[i])
def cmp(n1, n2):
new_n1 = "".join([m[c] for c in str(n1)])
new_n2 = "".join([m[c] for c in str(n2)])
return int(new_n1) - int(new_n2)
return sorted(nums, key=cmp_to_key(cmp))
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1721794620.A.944.html
→
07/24 12:17,
1年前
, 1F
07/24 12:17, 1F
推
07/24 12:19,
1年前
, 2F
07/24 12:19, 2F
推
07/24 12:20,
1年前
, 3F
07/24 12:20, 3F
討論串 (同標題文章)
完整討論串 (本文為第 558 之 1549 篇):