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 旋转整数的更多相关文章

  1. [LintCode] Reverse Integer 翻转整数

    Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). ...

  2. No.007 Reverse Integer

    7. Reverse Integer Total Accepted: 153147 Total Submissions: 644103 Difficulty: Easy Reverse digits ...

  3. LeetCode--No.007 Reverse Integer

    7. Reverse Integer Total Accepted: 153147 Total Submissions: 644103 Difficulty: Easy Reverse digits ...

  4. [leetcode]7. Reverse Integer反转整数

    Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...

  5. [Leetcode] reverse integer 反转整数

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...

  6. 7. Reverse Integer 反转整数

    [抄题]: 将一个整数中的数字进行颠倒,当颠倒后的整数溢出时,返回 0 (标记为 32 位整数).   样例 给定 x = 123,返回 321 给定 x = -123,返回 -321 [暴力解法]: ...

  7. 【LeetCode】7、Reverse Integer(整数反转)

    题目等级:Easy 题目描述: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 O ...

  8. 7. Reverse Integer[E]整数反转

    题目 Given a 32-bit signed integer, reverse digits of an integer. Example1: x = 123, return 321 Exampl ...

  9. 007. Reverse Integer

    题目链接:https://leetcode.com/problems/reverse-integer/description/ Given a 32-bit signed integer, rever ...

随机推荐

  1. bzoj 1185 最小矩形覆盖 —— 旋转卡壳

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1185 枚举一条边,维护上.左.右方的点: 上方点到这条边距离最远,所以用叉积求面积维护: 左 ...

  2. Java中的String数据类型

    本文主要是说明一些String数据类型的基本知识,有些杂乱,不过都是比较重要的东西,主要是参考了网上人的资料.原文网址:http://dev.yesky.com/91/2309091.shtml 主要 ...

  3. 删除老的Azure Blob Snapshot

    客户有这样的需求:每天需要对VM的数据进行备份,但如果备份的时间超过一定的天数,需要进行清除. 本文也是在前一篇Azure Blob Snapshot上的优化. "Azure blob St ...

  4. 移植完linux-3.4.2内核,启动系统后使用命令ifconfig -a查看网络配置,没有eth0

    问题: / # ifconfig / # ifconfig eth0  ifconfig: eth0: error fetching interface information: Device not ...

  5. C#事件触发机制

    C#的事件触发机制,类似于c++的回调函数机制 我先简单说一下,委托和事件的实质,后期再重开一篇博文来详细说 委托:指向方法的指针,类似于C的函数指针 事件:是一个可以存放0个或多个方法指针的数据结构 ...

  6. [51nod1384]全排列

    法一:next_permutation函数,两个参数分别为起始指针和末尾指针. #include<bits/stdc++.h> using namespace std; typedef l ...

  7. nodejs中 underscore 包有什么作用

    Underscore一个JavaScript实用库,提供了一整套函数式变成有用的实用功能,但是没有扩展任何JavaScript内置对象.它是这个问题的答案:“如果我在一个空白的HTML页面前坐下, 并 ...

  8. Command line option syntax error. Type Command /? for Help.

    --------------------------- Microsoft Visual C++ 2005 Redistributable --------------------------- Co ...

  9. 17、GATK使用简介 Part2/2

    转载:http://blog.sina.com.cn/s/blog_6721167201018jik.html Change Logs: 13/01/12: 增加了一篇文献,外加一些无聊的修改.12/ ...

  10. Appium 在 Android UI 测试中的应用

    原文地址:https://blog.coding.net/blog/Appium-Android-UI Android 测试工具与 Appium 简介 Appium 是一个 C/S 架构的,支持 An ...