leetcode-第14周双周赛-1271-十六进制魔术数字
自己的提交:
class Solution:
def toHexspeak(self, num: str) -> str:
num = hex(int(num))
num = str(num)[2:]
res = ""
for i in num:
if i == "":
i = "O"
if i == "":
i = "I"
i = i.upper()
if i not in {"A", "B", "C", "D", "E", "F", "I", "O"}:
return "ERROR"
res += i
return res
另:
class Solution:
def toHexspeak(self, num: str) -> str:
s = hex(int(num))[2:].upper()
def change(c):
if c == '':
return 'O'
elif c == '':
return 'I'
else:
return c
if len(list(filter(lambda c: c not in 'ABCDEF01', s))) != 0:
return "ERROR"
return "".join(list(map(lambda c: change(c), s)))
leetcode-第14周双周赛-1271-十六进制魔术数字的更多相关文章
- LeetCode 第 14 场双周赛
基础的 api 还是不够熟悉啊 5112. 十六进制魔术数字 class Solution { public: char *lltoa(long long num, char *str, int ra ...
- LeetCode 5112. 十六进制魔术数字 Hexspeak
地址 https://leetcode-cn.com/problems/hexspeak/ 题目描述字母大写的十六进制字符串,然后将所有的数字 0 变成字母 O ,将数字 1 变成字母 I . 如果 ...
- LeetCode第8场双周赛(Java)
这次我只做对一题. 原因是题目返回值类型有误,写的是 String[] ,实际上应该返回 List<String> . 好吧,只能自认倒霉.就当涨涨经验. 5068. 前后拼接 解题思路 ...
- Java实现 LeetCode第30场双周赛 (题号5177,5445,5446,5447)
这套题不算难,但是因为是昨天晚上太晚了,好久没有大晚上写过代码了,有点不适应,今天上午一看还是挺简单的 5177. 转变日期格式 给你一个字符串 date ,它的格式为 Day Month Yea ...
- LeetCode 第 15 场双周赛
1287.有序数组中出现次数超过25%的元素 1288.删除被覆盖区间 1286.字母组合迭代器 1289.下降路径最小和 II 下降和不能只保留原数组中最小的两个,hacked. 1287.有序数组 ...
- leetcode-第14周双周赛-1274-矩形内船只的数目
题目描述: 自己的提交: # """ # This is Sea's API interface. # You should not implement it, or s ...
- leetcode-第14周双周赛-1273-删除树节点
题目描述: 自己的提交:动态规划 class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: Lis ...
- leetcode-第14周双周赛-1272-删除区间
题目描述: 自己的提交: class Solution: def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[ ...
- leetcode-第12周双周赛-5111-分享巧克力
题目描述: 方法: class Solution: def maximizeSweetness(self, A: List[int], K: int) -> int: def possible( ...
随机推荐
- CNN基础四:监测并控制训练过程的法宝——Keras回调函数和TensorBoard
训练模型时,很多事情一开始都无法预测.比如之前我们为了找出迭代多少轮才能得到最佳验证损失,可能会先迭代100次,迭代完成后画出运行结果,发现在中间就开始过拟合了,于是又重新开始训练. 类似的情况很多, ...
- C++ 字符串截取转换及字符流控制
文章由来 ------------------工作需要缓冲区里的字符串控制,还是混合编译的那种,根据协议来定义截取各种字符流,控制大小长度,截取返回的内容然后转换成特定的类型, 可能表述不是那么正确, ...
- POJ 2299 Ultra-QuickSort (树状数组+离散化 求逆序数)
In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a seque ...
- bind-dns服务器搭建
环境:主服务器上IP为192.168.159.30 安装相关包bind dns服务器 bind-utils提供nslookup dig等命令 yum -y install bind bind-uti ...
- SPOJ_QTREE系列题解
QTREE4 #pragma comment(linker, "/STACK:102400000,102400000") //#include<bits/stdc++.h&g ...
- 51NOD 1005
1005 大数加法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出2个大整数A,B,计算A+B的结果. Input 第1行:大数A 第2行:大 ...
- 2017《Java学习》第二次作业 计科1502任秀兴
学习git总结 安装git 1. 安装完成后执行命令git --version查看版本 2.执行命令git config --global user.nam "你的用户名",执行命 ...
- Openstack组件实现原理 — Keystone认证功能
目录 目录 前言 Keystone安装列表 Keystone架构 Keystone的管理对象 一个理解Keystone管理对象功能的例子 Keystone管理对象之间的关系 Keystone V3的新 ...
- Gym 102021D : Down the Pyramid(思维)
Do you like number pyramids? Given a number sequence that represents the base, you are usually suppo ...
- upc组队赛12 Janitor Troubles【求最大四边形面积】
Janitor Troubles Problem Description While working a night shift at the university as a janitor, you ...