7. 反转整数(Reverse Integer) C++
知识点:
- 内置变量 INT_MAX INT_MIN
- 运算结果是否溢出的判断
- 判断pop>7即pop>INT_MAX%10
- 判断pop<-8即pop<INT_MIN%10
class Solution {
public:
int reverse(int x) {
int pop,ans=;
while(x)
{
pop = x%;
x /= ;
if(ans > INT_MAX/ || (ans == INT_MAX/ && pop >))
return ;
if(ans < INT_MIN/ || (ans == INT_MIN/ && pop <-))
return ;
//cout << "pop: " << pop << " ans: " << ans << '\n';
ans = ans* + pop;
}
return ans;
}
};
7. 反转整数(Reverse Integer) C++的更多相关文章
- [Swift]LeetCode7. 反转整数 | Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...
- Leetcode 7 反转整数Reverse Integer
给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 注意: ...
- LeetCode 7. 反转整数(Reverse Integer)
题目描述 给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 ...
- LeetCode 7 Reverse Integer(反转数字)
题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...
- Reverse Integer - 反转一个int,溢出时返回0
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- [LintCode] Reverse Integer 翻转整数
Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). ...
- leetCode(62)-Reverse Integer
题目: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 clic ...
- 【算法】LeetCode算法题-Reverse Integer
这是悦乐书的第143次更新,第145篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第2题(顺位题号是7),给定32位有符号整数,然后将其反转输出.例如: 输入: 123 ...
- leetcode:Reverse Integer 及Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
随机推荐
- Kylin知识点介绍
Kylin is an open source Distributed Analytics Engine from eBay Inc.that provides SQL interface and m ...
- Shell脚本(三)
摘自:菜鸟教程 http://www.runoob.com/linux/linux-shell-echo.html Shell命令 1. echo命令 字符串输出 echo "OK! \c& ...
- Javascript 高级程序设计(第3版) - 第01章
2017-05-10 js简介 一个叫“不难登”的人发明的.js的流行是因为 ajax 的关系. js分为三个部分: 核心: ECMAScript 文档对象模型: DOM 浏览器对象模型: BOM 核 ...
- Ajax - 发送请求原理
1,什么是ajax? Asynchronous JavaScript and XML(当然现在xml已经由json代替): 主要是用于前后台的交互(表单提交已经被废弃): 使用场景:前台获取数据.表单 ...
- R----ggplot2包介绍学习--转载
https://www.cnblogs.com/nxld/p/6059603.html 分析数据要做的第一件事情,就是观察它.对于每个变量,哪些值是最常见的?值域是大是小?是否有异常观测? ggplo ...
- dataTables使用整理(一)
初次使用dataTables,对一些用到的属性及遇到的问题做一个简要的记录 参考资料: http://blog.csdn.net/mickey_miki/article/details/8240477 ...
- 【二十二】mysqli事务处理与预处理总结
事务处理 事务基本原理 如果不开启事务,执行一条sql,马上会持久化数据.可见:默认的mysql对sql语句的执行是自动提交的! 如果开启了事务,就是关闭了自动提交的功能,改成了commit执行自动提 ...
- java 四种线程池的异同
四种线程池的区别仅仅在于executors让threadpoolexecutor的构造器的参数不同,即核心线程池数,最大线程池数等不同.但是其他的,例如终止线程池等都是一样的
- 串口.Qt532测试(异步)
环境:Win7x64.Qt5.3.2 MSVC OpenGL(x86).vs2010(x86) 项目所在位置:E:\Project_Qt532\SeriesPort_Qt532_Z ZC:这里 同步方 ...
- Qt5文件操作_保存成"UTF-8"格式
1. bool TdrawSvg::Save2File(char* _pcFullFileName) { // http://blog.csdn.net/u011314012/article/deta ...