当前位置:网站首页>(闲暇)LeetCode9. Palindrome Number
(闲暇)LeetCode9. Palindrome Number
2022-07-21 09:15:00 【phac123】
传送门.
学习点:
for i, j in zip(s, ss);可以同时遍历两个列表
一个int数字不能直接转列表。
C++代码:
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
string str;
while(x) {
str += '0' + x % 10;
x /= 10;
}
for(int i = 0, j = str.size() - 1; i != j && i < j; i ++, j --)
if(str[i] != str[j]) return false;
return true;
}
};
Python代码:
class Solution:
def isPalindrome(self, x: int) -> bool:
s = str(x); s = list(s)
ss = s[:]; ss.reverse()
# for i, j in zip(s, ss):
# if i != j:
# return False;
for i in range(0, len(s)):
if s[i] != ss[i]:
return False;
return True;
边栏推荐
- R语言ggplot2可视化:ggplot2可视化分组箱图,将可视化图像的图例(legend)放置在图像底部居中、其中图例信息水平平铺 (position legend bottom center)
- 安全之路 —— 单管道反向连接后门解析
- Chapter 3 business function development (to display the main page of clues and query the data of each drop-down box of the form)
- R语言使用fmsb包可视化雷达图(radar chart、蜘蛛图spider plot)、独立显示多个数据对象的雷达图、添加平均水平灰色区域、每个雷达图都和平均水平进行对比
- 最近的三个数之和
- 3537. Tree lookup
- js中批量修改对象中的属性值
- 3537. 树查找
- 过滤概念(可行性分析)
- The content of the architecture is excerpted from "happy when you smell defects" (this book can be downloaded for free)
猜你喜欢
随机推荐
分布式事务之二阶段提交、AT模式、TCC模式
[deep learning notes] attention mechanism
RedisGraph图形数据库多活设计方案
为Kubernetes选择合适的容器运行时
M using Verilog to develop GMSK modulator based on FPGA under ISE platform
【213】go语言问的比较多的面试题
rust中的静态分发和动态分发
weirdo A company's interview questions asked about toilet habits, eating time, sleeping time, etc
过滤概念(可行性分析)
字节跳动确认将自研芯片:仅供内部使用;马斯克:我已将大脑上传云端;Go 语言产品负责人离职|极客头条...
马斯克把大脑上传云端?周鸿祎:还得要用人脑安全卫士杀个毒
奇葩!一公司面试题竟问如厕习惯、吃饭时长、入睡时间等
3511. Water pouring problem
HCIP第七天笔记
3564. 日期类
sql中substr与substring函数用法
How to use the order flow analysis tool (Part 1)
SkyWalking集成日志框架、告警、高可用集群搭建
C#入门系列(二十六) -- 程序集和命名空间
Tencent techo hub landed in Fuzhou 723 for the first time in 2022 to discuss industrial digitalization with developers!