LeetCode刷题(C++)——Reverse Integer(Easy)
来源:互联网 发布:2016淘宝店好做吗 编辑:程序博客网 时间:2024/06/05 16:10
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
click to show spoilers.
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.
Note:
The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
class Solution {public: int reverse(int x) { const int max = INT_MAX; const int min = INT_MIN; long sum = 0; while(x) { int temp = x%10; sum = sum*10+temp; if(sum>max||sum<min) return 0; x = x/10; } return sum; }};
- LeetCode刷题(C++)——Reverse Integer(Easy)
- Reverse Integer(EASY)
- 【Leetcode】Reverse Integer(easy)
- 7. Reverse Integer (Easy)
- LeetCode-Easy刷题(2) Reverse Integer
- leetcode第七题(easy)——Reverse Integer
- LeetCode 第7题 Reverse Integer (easy)——python
- LeetCode-7-Reverse Integer(Nmber-Strng)-Easy
- LeetCode刷题(C++)——Roman to Integer(Easy)
- 【LeetCode算法练习(C++)】Reverse Integer
- 【leetcode】7. Reverse Integer(Python & C++)
- [leetcode]Reverse Integer 代码(C++)
- [Leetcode 7, Easy] Reverse integer
- 【LeetCode】(7)Reverse Integer(Easy)
- LeetCode #7 - Reverse Integer - Easy
- leetcode—Reverse Integer
- [LeetCode] 007. Reverse Integer (Easy) (C++/Java/Python)
- Easy 2 Reverse Integer(7)
- jQuery判断checkbox是否选中
- Thinking in java
- servlet web2.5到web3.0后jsp的EL表达式不能解析(servlet降级方法)【本质原因找到】
- mysqld: File './mysql-bin.index' not found (Errcode: 13
- CSU 1908: The Big Escape
- LeetCode刷题(C++)——Reverse Integer(Easy)
- 多线程学习笔记(四)之线程间通信---等待唤醒机制
- 监控集群的状态
- 梯度下降法(BGD,SGD,MSGD)python+numpy具体实现
- Lecture 11: Hopfield Nets
- JAVA使用JOONE实现神经网络的官网例子
- 算法分析与设计课程07——330. Patching Array(Hard)
- 先来先服务算法(FCFS)和 短作业优先算法(SJF)
- 编码练习——Java-6-类的高级特性