Re: [閒聊] 每日leetcode

作者: dont   2024-07-24 10:37:34
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)
```
作者: digua (地瓜)   2024-07-24 10:38:00
你版怎麼多一堆程式大師

Links booklink

Contact Us: admin [ a t ] ucptt.com