Reverse Integer(C++)
来源:互联网 发布:会计电算软件 编辑:程序博客网 时间:2024/06/03 03:40
7.Reverse digits of an integer.
Problem descriptions:
Example1: x = 123, return 321
Example2: x = -123, return -321
Difficulty:Easy
class Solution {
public:
int reverse(int x) {
long long int y= 0,z=0;
int res = 0;
z = x;
if(x<0)
{
z = -z;
}
y = z%10;
z = z/10;
while(z>0)
{
y = y * 10 + z%10;
z = z /10;
}
if(x<0)
{
y = -y;
}
if (y >= INT_MAX)
{
res = 0;
}
else if (y<= INT_MIN)
{
res = 0;
}
else
{
res = (int)y;
}
return res;
}
};
注意正负、取值范围就OK了
0 0
- 【leetcode c++】Reverse Integer
- 007Reverse Integer (C)
- Reverse Integer(C++)
- LeetCode Reverse Integer(C)
- [C++]LeetCode: 17 Reverse Integer
- LeetCode::Reverse Integer C语言
- C实现 LeetCode->Reverse Integer
- [C++]Reverse Integer整数翻转
- [leetcode]Reverse Integer C语言
- Leetcode c语言-Reverse Integer
- reverse integer 之 c c++ python java
- 【leetcode-7】Reverse Integer(C语言)
- 【leetcode-7】Reverse Integer(C语言)
- 【C语言】LeetCode 7. Reverse Integer
- 2---LeetCode【Reverse Integer】|C语言|总结
- 【LeetCode算法练习(C++)】Reverse Integer
- 【leetcode】7. Reverse Integer(Python & C++)
- [leetcode]Reverse Integer 代码(C++)
- shiro认证入门程序
- Android注解支持(Support Annotations)
- jquery 设置style:display的方法
- Spring框架 教程
- 《Linux内核设计与实现》笔记——进程调度
- Reverse Integer(C++)
- struts2 url传参中文乱码
- 栈-中缀式转后缀式
- Struts2学习(九)—拦截器之登录权限
- HDU5023(A Corrupt Mayor's Performance Art)(第一个a了的pascal)
- Android中关闭应用的三种方式
- 深度学习语义分割
- xmemcached使用的几点优化建议
- Nginx+Lua开发入门