首页 > 其他 > 详细

leetcode1271

时间:2019-12-01 10:17:21      阅读:75      评论:0      收藏:0      [点我收藏+]
 1 class Solution:
 2     def toHexspeak(self, num: str) -> str:
 3         dic = {‘a‘:‘A‘,‘b‘:‘B‘,‘c‘:‘C‘,‘d‘:‘D‘,‘e‘:‘E‘,‘f‘:‘F‘,‘1‘:‘I‘,‘0‘:‘O‘}
 4         dn_10 = int(num)
 5         dn_16 = hex(dn_10)#10进制转16进制
 6         str_16 = str(dn_16)[2:]#去掉前缀 0x
 7         r = ‘‘
 8         for i in range(len(str_16)):
 9             if str_16[i] in dic:
10                 r += dic[str_16[i]]
11             else:
12                 return ‘ERROR‘
13         return r

 

leetcode1271

原文:https://www.cnblogs.com/asenyang/p/11965104.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!