LeetCode7: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.
int reverse(int x) {
int num_new=;
int num_remain=x;
int digit; while (num_remain != )
{
digit = num_remain%;
if (num_new > INT32_MAX/ || num_new < INT32_MIN/)
{
return ;
}
num_remain = num_remain/;
num_new =digit+num_new*; } return num_new; }
LeetCode7:Reverse Integer的更多相关文章
- Leetcode7 : Reverse Integer 整数反转问题
问题描述 Example1: x = 123, return 321 Example2: x = -123, return -321 原题链接: https://leetcode.com/proble ...
- 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, ...
- No.007 Reverse Integer
7. Reverse Integer Total Accepted: 153147 Total Submissions: 644103 Difficulty: Easy Reverse digits ...
- 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 ...
随机推荐
- Asp.Net使用代理IP远程获取数据
/// <summary> /// 远程获取数据 /// </summary> /// <param name="url">url</pa ...
- UVa725 - Division
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; int ...
- js sleep效果
js sleep效果 s = setInterval(function(){ //需要执行的函数 alert("我延迟了2秒弹出"); },2000); 并不是每2秒执行一次,而是 ...
- LA 2995 Image Is Everything 立方体成像 World Final 2004
有一个 n * n * n 的立方体,其中一些单位立方体已经缺失(剩下部分不一定连通).每个单位立方体重 1 克,且被涂上单一的颜色(即 6 个面的一颜色相同).给出前.左.后.右.顶.底 6 个视图 ...
- StringUtils判断字符串是否为空的方法
public static boolean isEmpty(String str) 判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0 下面是 Stri ...
- 在Android中使用并发来提高速度和性能
Android框架提供了很实用的异步处理类.然而它们中的大多数在一个单一的后台线程中排队.当你需要多个线程时你是怎么做的? 众所周知,UI更新发生在UI线程(也称为主线程).在主线程中的任何操作都会阻 ...
- AJax学习一
1.Ajax的准备工作,就是要先准备好服务器环境. 这边可以有好几种方式,例如服务器工具: http://www.php100.com/html/plugin/ser/2013/0905/91.htm ...
- Python time mktime()方法
描述 Python time mktime() 函数执行与gmtime(), localtime()相反的操作,它接收struct_time对象作为参数,返回用秒数来表示时间的浮点数. 如果输入的值不 ...
- 页面异步加载javascript文件
昨天听一同事说的异步加载js文件,可以提高页面加载速度.具体方法如下:(function() { var ga = document.createElement('script'); ga.type ...
- shell脚本中一些特殊符号
在shell中常用的特殊符号罗列如下: # ; ;; . , / \\ 'string'| ! $ ${} $? $$ $* \"string\"* ** ...