Leecode刷题之旅-C语言/python-9.回文数
/*
* @lc app=leetcode.cn id=9 lang=c
*
* [9] 回文数
*
* https://leetcode-cn.com/problems/palindrome-number/description/
*
* algorithms
* Easy (56.02%)
* Total Accepted: 75.3K
* Total Submissions: 134.4K
* Testcase Example: '121'
*
* 判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
*
* 示例 1:
*
* 输入: 121
* 输出: true
*
*
* 示例 2:
*
* 输入: -121
* 输出: false
* 解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。
*
*
* 示例 3:
*
* 输入: 10
* 输出: false
* 解释: 从右向左读, 为 01 。因此它不是一个回文数。
*
*
* 进阶:
*
* 你能不将整数转为字符串来解决这个问题吗?
*
*/
bool isPalindrome(int x) {
long i = ;
long t = x;
while(t){
i = i*+(t%);
t = t/;
}
if(i==x&&i>=){
return true;
}
else
{
return false;
}
}
这里提交了几次有遗漏,其实就应用了 7.整数反转的算法,判断反转后的和反转前是否相等就可以。
这里要注意,负数肯定不是回文数,0是回文数,要注意这个条件。
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
python:
其实与c类似,如果说能简单的话就是可以变成字符串操作,但是本质还是一样的。这就不详细写了。
Leecode刷题之旅-C语言/python-9.回文数的更多相关文章
- Leecode刷题之旅-C语言/python-1.两数之和
开学后忙的焦头烂额(懒得很),正式开始刷leecode的题目了. 想了想c语言是最最基础的语言,虽然有很多其他语言很简单,有更多的函数可以用,但c语言能煅炼下自己的思考能力.python则是最流行的语 ...
- Leecode刷题之旅-C语言/python-387 字符串中的第一个唯一字符
/* * @lc app=leetcode.cn id=387 lang=c * * [387] 字符串中的第一个唯一字符 * * https://leetcode-cn.com/problems/f ...
- Leecode刷题之旅-C语言/python-28.实现strstr()
/* * @lc app=leetcode.cn id=28 lang=c * * [28] 实现strStr() * * https://leetcode-cn.com/problems/imple ...
- Leecode刷题之旅-C语言/python-7.整数反转
/* * @lc app=leetcode.cn id=7 lang=c * * [7] 整数反转 * * https://leetcode-cn.com/problems/reverse-integ ...
- Leecode刷题之旅-C语言/python-434 字符串中的单词数
/* * @lc app=leetcode.cn id=434 lang=c * * [434] 字符串中的单词数 * * https://leetcode-cn.com/problems/numbe ...
- Leecode刷题之旅-C语言/python-326 3的幂
/* * @lc app=leetcode.cn id=326 lang=c * * [326] 3的幂 * * https://leetcode-cn.com/problems/power-of-t ...
- Leecode刷题之旅-C语言/python-263丑数
/* * @lc app=leetcode.cn id=263 lang=c * * [263] 丑数 * * https://leetcode-cn.com/problems/ugly-number ...
- Leecode刷题之旅-C语言/python-383赎金信
/* * @lc app=leetcode.cn id=383 lang=c * * [383] 赎金信 * * https://leetcode-cn.com/problems/ransom-not ...
- Leecode刷题之旅-C语言/python-349两整数之和
/* * @lc app=leetcode.cn id=371 lang=c * * [371] 两整数之和 * * https://leetcode-cn.com/problems/sum-of-t ...
随机推荐
- GridView——标题行自适应单元格列宽与选中单元格变色
首先看效果图: 主要实现—— 1.前台GridView代码: <asp:GridView Height="100%" Width="98%" ID=&qu ...
- php 获取毫秒时间戳
function getMsec(){//返回毫秒时间戳 $arr = explode(' ',microtime()); $hm = 0; foreach($arr as $v){ $hm += f ...
- Win+Tab键实现自定义程序列表间的窗口切换
程序是用AutoHotkey语言写的, 说明: 以自己使用频率的顺序在ExeList自定义的程序间切换 切换可以以所有窗口切换,也可以按程序组切换(比如在word窗口间切换) 程序组可以分别定义排除的 ...
- 发送请求获取响应内容(c#)
C#请求url,获取响应的脚本 public string ResultOfApi(string url) { //发送请求 HttpWebRequest request = null; HttpWe ...
- ACM-ICPC(10 / 9)
ACM-ICPC(10.9) 树形DP 树形DP考点很多,状态转移有时会很复杂,但是也有规律可寻,最重要的是抓住父子关系之间的状态转移. 树的最大独立集:尽量选择多的点,使得任何两个结点均不相邻. ...
- Uva 10061 进制问题
题目大意:让求n!在base进制下的位数以及末尾0的连续个数. 多少位 log_{10}256=log_{10}210^2+log_{10}510^1+log_{10}6*10^0 可以发现,只和最高 ...
- 【luogu P1494 [国家集训队]小Z的袜子】 题解
题目链接:https://www.luogu.org/problemnew/show/P1494 #include <cstdio> #include <algorithm> ...
- C#多线程最简单Demo
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- ipython notebook开通远程
之前只是会用,别人告诉我命令和大概怎么设置的,今天自己搭建才发现一知半解搞不定啊. 目的:远程通过ipython notebook调用服务器. 服务器是ubuntu16.04 本地机器win7 配置方 ...
- android(eclipse)广播机制知识梳理(三)
1:分类: 标准广播:没有先后顺序,无法被截断 有序广播:又先后顺序,可以截断 2:接收广播:首先进行注册,注册的方式有静态注册和动态注册.也就是在代码中注册和在AndroidManifest ...