Re: [閒聊] 每日leetcode已回收

看板Marginalman作者 (dont)時間1年前 (2024/07/24 10:37), 編輯推噓0(001)
留言1則, 1人參與, 1年前最新討論串555/1549 (看更多)
2191. Sort the Jumbled Numbers ## 思路 寫個convert func轉換新數字 再根據這func排序原本的數列 ## Code ```python class Solution: def sortJumbled(self, mapping: List[int], nums: List[int]) -> List[int]: def convert(num): # corner case if num == 0: return mapping[num] res, shift = 0, 1 while num: num, digit = divmod(num, 10) res += shift * mapping[digit] shift *= 10 return res return sorted(nums, key=convert) ``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.43 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1721788656.A.CB2.html

07/24 10:38, 1年前 , 1F
你版怎麼多一堆程式大師
07/24 10:38, 1F
文章代碼(AID): #1ce6Zmoo (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ce6Zmoo (Marginalman)