Reverse digits of an integer.
class Solution {
public:
int reverse(int x) {
;//long 是怕中间过程溢出
<<,max=-min-){
ans=ans*+x%;
x=x/;
}
if(ans>max||ans<min)
;
return ans;
}
};
注释:
这是进制转换问题。
转化过程中一定要考虑溢出。
清楚各种类型的表示范围。
附
32位平台:
unsigned int 0~4294967295
int -2147483648~2147483647 (-2^31~(2^31-1))//补码比原码多表示1个数
unsigned long 0~4294967295
long -2147483648~2147483647
long long的最大值:9223372036854775807
long long的最小值:-9223372036854775808
unsigned long long的最大值:1844674407370955161
__int64的最大值:9223372036854775807
__int64的最小值:-9223372036854775808
unsigned __int64的最大值:18446744073709551615
Reverse digits of an integer.的更多相关文章
- 【LeetCode】Reverse digits of an integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Have you ...
- 【leetcode】1281. Subtract the Product and Sum of Digits of an Integer
题目如下: Given an integer number n, return the difference between the product of its digits and the sum ...
- 翻转整数 Reverse digits of a number
两种方法翻转一个整数.顺序翻转和递归翻转 这里没考虑overflow的情况 递归的作用是使得反向处理.即从递归栈的最低端開始处理.通过绘图可得. 假设是rec(num/10): 12345 1234 ...
- [Leetcode] 5279. Subtract the Product and Sum of Digits of an Integer
class Solution { public int subtractProductAndSum(int n) { int productResult = 1; int sumResult = 0; ...
- LeetCode 7. Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have you ...
- [LeetCode] Reverse Integer 翻转整数
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to ...
- Reverse Integer LeetCode Java
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 public cl ...
- No.007:Reverse Integer
问题: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321 官方难度: Ea ...
- Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 public cl ...
随机推荐
- angular ng-bind-html 对src路径失效 解决方案
json内容 ;<img src="/newsfile/1506271512489.jpg" width="600" height="450&q ...
- tomcat 显示目录文件列表
conf/web.xml中,listings改为true,重启 http://liusu.iteye.com/blog/794613 <servlet> <servlet-name& ...
- HTML&CSS基础学习笔记1.25-input标签隐藏元素
隐藏元素 有时候我们编写前端代码的时候,可能需要把一些数据告诉后台,但是这些数据又不想让用户看到,我们可以设置<input>标签的[type]属性为"hidden". ...
- C语言初学 计算三角形面积问题
#include<stdio.h> #include<math.h> #include<stdlib.h> int main() { float a,b,c,s,a ...
- IOS多线程 总结 -------------核心代码(GCD)
//NSObject //在子线程中执行代码 // 参数1: 执行的方法 (最多有一个参数,没有返回值) //参数2: 传递给方法的参数 [self performSelectorInBackgrou ...
- Debian/Ubuntu 安装bcm43142无线网卡驱动
Drivers for Broadcom BCM43142 wireless card of Ubuntu/Debian 64-bit Linux 1.Check the wireless card ...
- Feedly订阅Blog部落格RSS网摘 - Blog透视镜
网络信息爆炸的时代,如何更有效率地阅读文章,订阅RSS网摘,可以快速地浏览文章标题,当对某些文章有兴趣时,才点下连结连到原网站,阅读更详细的文章,Feedly Reader阅读器除了提供在线版订阅RS ...
- 阅读记录:Learning multiple layers of representation(杂乱笔记)
典型的浅层学习结构: 传统隐马尔可夫模型(HMM).条件随机场 (CRFs).最大熵模型(Maxent).支持向量机(SVM).核回归及仅含单隐层的多层感知器(MLP)等. 局部表示,分布式表示和稀疏 ...
- Android获取文件夹路径 /data/data/
首先内部存储路径为/data/data/youPackageName/,下面讲解的各路径都是基于你自己的应用的内部存储路径下.所有内部存储中保存的文件在用户卸载应用的时候会被删除. 一. files1 ...
- Powershell Switch 条件
Powershell Switch 条件 6 21 1月, 2012 在 Powershell tagged Powershell教程/ 分支/ 字符串/ 数字/ 条件by Mooser Lee 本 ...