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 ...
随机推荐
- [转]Mac App distribution in App Store
Mac程序的大包上传和iOS的有些许不同,因为Mac app既可以上传到store,也可以不通过store供人下载.因此,code sign和provision要根据情况(开发,release< ...
- php 之 数据访问 增删改查练习题
练习题内容: 一.查看新闻页面-----主页面: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- mongodb spring
可参考 http://blog.csdn.net/cuiran/article/details/8287204 我修改后的代码 http://pan.baidu.com/s/1mgJYbaC
- Android性能优化学习
工作以来,越来越觉得性能优化的重要性,从技术角度,它甚至成了决定一个app成败的最关键因素.因此,特地花时间去学习专研性能优化的方法. 学习性能优化最便捷的方式便是研读别人有关性能优化的博客,然而网上 ...
- ida idc函数列表全集
下面是函数描述信息中的约定: 'ea' 线性地址 'success' 0表示函数失败:反之为1 'void'表示函数返回的是没有意义的值(总是0) AddBptEx AddBpt AddCodeXre ...
- python 3.5 猜数字游戏
#!/usr/bin/env python #encoding: utf-8 number = 88 for i in range(1,6): num = int(input('gusee numbe ...
- Lintcode--010(最长上升子序列)
给定一个整数序列,找到最长上升子序列(LIS),返回LIS的长度.LIS(longestIncreasingSubsequence) 说明: 最长上升子序列的定义: 最长上升子序列问题是在一个无序的给 ...
- 在 Windows 下部署 Go 语言环境
http://bbs.chinaunix.net/thread-4088281-1-1.html 1. 首先下载官方二进制安装包:32 位选择 windows-386.msi64 位选择 window ...
- JVM试用G1的垃圾收集器
因为以前用默认的GC,,老年代经常在占比超过99%才发生一个GC行为,感觉不爽...尽管每次FULL GC只要0.5S. 结合上次听中华构架师大会,一哥们分享的G1 GC...试试.. 就在TOMCA ...
- How can I let the compiled script depend on something dynamic
Compile your script with /DNAME=value or /X"nsis command" passed on to makensis.exe as com ...