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 ...
随机推荐
- BZOJ 1589 采集糖果
23333怎么调了一晚上.... #include<iostream> #include<cstdio> #include<cstring> #include< ...
- 解决Eclipse快捷键被其他软件占用
做为一个java攻城狮,eclipse是我最常用的攻城设备,eclipse快捷键 极大的提高了我的开发效率!!!! 前段时间升级了一下我的战斗装备——给电脑的系统盘换成了一个固态硬盘,因此需要重装系统 ...
- mysql,多对多的hibernate操作对应的jdbc操作
在hibernate中oo思想操作数据库,很方便,但是需要了解一下底层的jdbcsql是怎么写的,复习 多对多的表关系,取出,id为1的学生 订阅了哪些课程? mysql> select c_n ...
- 【英语】Bingo口语笔记(71) - shit系列
- T-SQL备忘(4):分页
set statistics io on set statistics time on --SQL Server 2012分页方式 select * from Production.Product o ...
- HDU 4662 MU Puzzle 2013 Multi-University Training Contest 6
现在有一个字符串"MI",这个字符串可以遵循以下规则进行转换: 1.Mx 可以转换成 Mxx ,即 M 之后的所有字符全部复制一遍(MUI –> MUIUI) 2.III 可 ...
- http tcp联系区别
术语TCP/IP代表传输控制协议/网际协议,指的是一系列协议.“IP”代表网际协议,TCP和UDP使用该协议从一个网络传送数据包到另一个网络.把IP想像成一种高速公路,它允许其它协议在上面行驶并找到到 ...
- 【python】python+behave自动化
留坑,后面再写,先写下request对http请求的校验.
- 网页元素定位神器之Xpath详解
摘要: 经常在工作中会使用到XPath的相关知识,但每次总会在一些关键的地方不记得或不太清楚,所以免不了每次总要查一些零碎的知识,感觉即很烦又浪费时间,所以对XPath归纳及总结一下. ... ...
- Real Boxing 2
http://itunes.apple.com/ca/app/real-boxing-2/id932779605?mt=8&ign-mpt=uo%3D4