Leetcode每日一道 -- 整数反转
2018-11-28 23:07
423 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_19332527/article/details/84594073
今天有点儿偷懒,选择刷了最简单的一个入门题。直接上代码
[code]class Solution { public: int reverse(int x) { long long res=0; while(x!=0) { res=res * 10 + x % 10 ; x /= 10; } return (res>INT_MAX || res<INT_MIN) ? 0:int(res) ; } };
知识点:C++中的INT_MAX和INT_MIN是可以调用的。
(1). 整型和字符型需要引入 limist.h 文件. 具体名称见链接 : https://msdn.microsoft.com/en-us/library/7fh3a000.aspx
(2).浮点型需要引入 float.h 文件. 代码如下:
[code]#include<stdio.h> #include <limits.h> #include <float.h> int main() { printf("int max is %d,int min is %d\n",INT_MAX,INT_MIN); printf("unsigned int max is %d\n",UINT_MAX); //注UINT 没有最小边界的定义,因为就是0 printf("long max is %d,long min is %d\n",LONG_MAX,LONG_MIN); printf("float max is %f, float min is %f\n",FLT_MAX,FLT_MIN); printf("double max is %lf, double min is %lf\n",DBL_MAX,DBL_MIN); }
阅读更多
相关文章推荐
- (LeetCode每日一刷02)反转整数
- 每日一道算法题:字符串反转
- LeetCode 7 :Reverse Integer ---- 反转int整数
- LeetCode:第7题: 反转整数(reverse-integer)
- LeetCode Reverse Integer 反转整数
- [置顶] [LeetCode] Reverse Integer 整数反转
- [leetcode] Reverse Integer 反转一个整数
- leetcode_7. Reverse Integer 反转整数的各个数字
- LeetCode7——Reverse Integer(将一个整数反转,注意溢出的处理)
- 每天一道LeetCode-----一个整数序列,每个元素出现两次,只有一个(两个)出现一次,找到这个(这两个)元素
- (LeetCode)反转整数
- [leetcode]反转整数
- 【leetcode】Reverse Integer整数反转----Java代码实现
- leetcode中文(一) #7反转整数,#77组合
- 每日一道算法题:Google面试题:给定能随机生成整数1到5的函数,写出能随机生成整数1到7的函数
- 【LeetCode】- Reverse Integer(将一个整数反转)
- leetcode 7. Reverse Integer整数反转
- [LeetCode-7] Reverse Integer(反转整数)
- Leetcode Reverse Integer 反转整数
- LeetCode里的7.反转整数问题 Java15行