007 Reverse Integer 旋转整数
Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
Input: 123
Output: 321
Example 2:
Input: -123
Output: -321
Example 3:
Input: 120
Output: 21
Note:
Assume we are dealing with an environment which could only hold integers within the 32-bit signed integer range. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
详见:https://leetcode.com/problems/reverse-integer/description/
实现语言:Java
class Solution {
public int reverse(int x) {
int res = 0;
while (x != 0) {
if (res > Integer.MAX_VALUE / 10 || res < Integer.MIN_VALUE / 10) {
return 0;
}
res = res * 10 + x % 10;
x /= 10;
}
return res;
}
}
实现语言:C++
class Solution {
public:
int reverse(int x) {
long res=0;
while(x)
{
res=res*10+x%10;
x/=10;
}
return (INT_MAX<res||INT_MIN>res)?0:res;
}
};
007 Reverse Integer 旋转整数的更多相关文章
- [LintCode] Reverse Integer 翻转整数
Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). ...
- No.007 Reverse Integer
7. Reverse Integer Total Accepted: 153147 Total Submissions: 644103 Difficulty: Easy Reverse digits ...
- LeetCode--No.007 Reverse Integer
7. Reverse Integer Total Accepted: 153147 Total Submissions: 644103 Difficulty: Easy Reverse digits ...
- [leetcode]7. Reverse Integer反转整数
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...
- [Leetcode] reverse integer 反转整数
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...
- 7. Reverse Integer 反转整数
[抄题]: 将一个整数中的数字进行颠倒,当颠倒后的整数溢出时,返回 0 (标记为 32 位整数). 样例 给定 x = 123,返回 321 给定 x = -123,返回 -321 [暴力解法]: ...
- 【LeetCode】7、Reverse Integer(整数反转)
题目等级:Easy 题目描述: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 O ...
- 7. Reverse Integer[E]整数反转
题目 Given a 32-bit signed integer, reverse digits of an integer. Example1: x = 123, return 321 Exampl ...
- 007. Reverse Integer
题目链接:https://leetcode.com/problems/reverse-integer/description/ Given a 32-bit signed integer, rever ...
随机推荐
- 利用SharedRegion实现核间共享
导入SharedRegion模块 SharedRegion模块是一个共享区域,特别是对于多处理器环境下,SharedRegion模块就是用于让一个内存区域能被不同处理器共享并操作.这个模块会给每个处理 ...
- web攻击之七:常见CDN回源问题总结
1. URL链接出现非法链接 (如 */./Play/show/id/349281 ); 2. CDN接收未知Referer处理失效(目前搜索引擎的状态码为499); 3. CDN抓取服务器 Cach ...
- JAVA 1.5 并发之 BlockingQueue
1.BlockingQueue 顾名思义就是阻塞队列 最经典的使用场合就是 生产者 - 消费者 模型啦,其优点是队列控制已经处理好,用户只需要存(满了会阻塞),取(空了会阻塞) 可以更多的关心核心逻辑 ...
- VMware VirtualCenter Server service fails to start with the vpxd.log error: ODBC error: (28000) (1017688)
Symptoms If you experience an ungraceful shutdown of the database (for example, because of a power o ...
- eclipse tomcat 无法加载导入的web项目,There are no resources that can be added or removed from the server. .
应该是项目自己的setting文件夹下的描述信息和.project文件的描述信息,不能适用于这个eclipse和tomcat. 解决方法: 1,找相同类型的工程(tomcat能引用的)2,把新建项目里 ...
- Mac For Mongodb安装启动、停止及启动授权
1.到Mongodb官网下载相应的安装包 地址:https://www.mongodb.com/download-center?jmp=nav#community 2.Mac Mongodb安装过程 ...
- Asp.net 实现只能允许一个账号同时只能在一个地方登录
先上帮助类: /// <summary> /// 单点登录帮助类 /// </summary> public class SSOHelper { /// <summary ...
- redis的 key string hash list set sorted set 常用的方法
redis 安装文件: http://blog.csdn.net/tangsilai/article/details/7477961 ============================== ...
- 【253】◀▶IEW-Unit18
Unit 18 International Events 1.model1对应题目分析 The Olympic Games is a major international sporting even ...
- Learning Python 011 高级特性 1
Python 高级特性 1 切片 将L = ['Michael', 'Sarah', 'Tracy', 'Bob', 'Jack']列表中前上个3个元素: L = ['Michael', 'Sarah ...