[Math]Reverse Integer
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!
If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
class Solution {
public:
int reverse(int x) {
int sign = ;
if(x<) {
sign=-;
x=-x;
}
long long int res = ;
while(x){
res = res* + x%;
x/=;
}
res *= sign;
res = res>INT_MAX || res<INT_MIN ? :res;
return res;
}
};
[Math]Reverse Integer的更多相关文章
- leetcode第七题Reverse Integer (java)
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, retu ...
- Reverse Integer 2015年6月23日
题目: Reverse digits of an integer. Example1: x = , return Example2: x = -, return - 思路:递归 解答: / test ...
- Reverse Integer - 反转一个int,溢出时返回0
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- LeetCode之Easy篇 ——(7)Reverse Integer
7.Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: Out ...
- LeetCode: Reverse Integer 解题报告
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- Python字符串倒序-7. Reverse Integer
今天做了下LeetCode上面字符串倒序的题目,突然想Python中字符串倒序都有哪些方法,于是网上查了下,居然有这么多种方法: 个人觉得,第二种方法是最容易想到的,因为List中的reverse方法 ...
- [LintCode] Reverse Integer 翻转整数
Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). ...
- 65. Reverse Integer && Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, re ...
- LeetCode 7 Reverse Integer(反转数字)
题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...
随机推荐
- UGUI学习之InputField
密码框在Context type 设置为Passwold 设置背景和调整字体颜色与透明度. 还有一个就是Toggle,(开关)要指定他的Graphic.
- FZU1327 优先队列
Problem 1327 Blocks of Stones II Accept: 318 Submit: 881Time Limit: 1000 mSec Memory Limit : 3 ...
- socket原理详解
1.什么是socket 我们知道进程通信的方法有管道.命名管道.信号.消息队列.共享内存.信号量,这些方法都要求通信的两个进程位于同一个主机.但是如果通信双方不在同一个主机又该如何进行通信呢?在计算机 ...
- (原)C++中测试代码执行时间
转载请注明出处(不过这个用法网上到处都是): http://www.cnblogs.com/darkknightzh/p/4987738.html LARGE_INTEGER nFreq, nBegi ...
- MySql学习之数据库管理
一步一步学习mysql数据,首先是mysql数据的管理操作. 1. 创建数据库 命令格式:create database [if not exists] database_name. 实际的使用过程中 ...
- easyui page添加文本,js验证码
onLoadSuccess: function (db) { //db是后台数据的返回结果集 $.ajax({ url: "AjaxSource/Buex.ashx", data: ...
- Mac OSX下面的博客客户端Marsedit使用
在windows下面,有一个很好用的博客客户端,叫做windows live writer,不得不感叹,其所见即所得的方面真的是很方便,特别是还可以方便的把word上的内容直接帖上去,包括文件中 ...
- 解决 setOnItemClickListener,setOnScrollListener与setOnTouchListener事件冲突问题
代码案例如下: lvXxsdMore.setOnItemClickListener(xxsdMoreListener); //对listView 注册onclick事件 lvXxsdMore.setO ...
- JS 函数中返回另一个函数
function createComparisonFunction(propertyName) { return function (object1, object2) { var value1 = ...
- USB class总结
以下是总结的USB的类,不同的USB类,主机询问的描述符格式和内容都不一样,具体的descriptor的内容可以查看 USB spec(http://www.usb.org/home/),如HID的s ...