当前位置:网站首页>LeetCode每日两题02:回文数 (均1200道)
LeetCode每日两题02:回文数 (均1200道)
2022-08-06 01:58:00 【那人独钓寒江雪.】

- 解题思路:首先将整数类型转换为字符串类型,然后进行遍历,数组长度/2 因为回文日期倒序相等,第一位数和倒数第一位数相等 第二位数与倒数第二位数相等,以此类推,如果不相等就返回false,如果相等则返回true
class Solution {
public boolean isPalindrome(int x) {
String str = x + "";//1221 运行两次
for (int i = 0; i < str.length() / 2; i++) {
if (str.charAt(i) != str.charAt(str.length() - 1 - i)) {
要减去一 因为是从0开头不是从1开头 return false;
}
}
return true;
}
}
边栏推荐
猜你喜欢
随机推荐
【hiflow】-- 腾讯云场景连接器实现定时查询疫情信息
【HCIP】BGP实验
codeforces 50A.Domino piling
浏览器缓存太多怎么办,清理浏览器缓存的方法
剑指offer专项突击版第21天
第十八天笔记
案例|工业物联网解决方案•工业互联网云平台
拦截器通过自定义注解来判断是否拦截
使用MySQL截取JSON串,结果为null
ansible ping 模块
MVCC interview questions
一体机的思考
MVCC面试题
CAN turn 4 g remote passthrough record cloud gateway for engineering machinery CAN assign
TS(TypeScript) 二元运算符 + , - , * , / , % , << , >> , >>> , & , | , ^ 分析
typescript72 - Existing type declaration files (type files for third-party libraries)
Data development experience
ansible copy 模块
【刷题系列】顺序表OJ题
typescript73-创建自己的类型声明文件(项目内共享类型)









