[leetcode] 7. Reverse Integer (easy)
水题 唯一注意的点就是数字溢出
class Solution
{
public:
int reverse(int x)
{
long long MAX = ((long long)1 << 31) - 1;
long long MIN = 0 - (1 << 31);
long long a = 0;
while (x)
{
a = a * 10 + x % 10;
x /= 10;
}
return a > MAX || a < MIN ? 0 : a;
}
};
[leetcode] 7. Reverse Integer (easy)的更多相关文章
- Leetcode 7. Reverse Integer(水)
7. Reverse Integer Easy Given a 32-bit signed integer, reverse digits of an integer. Example 1: Inpu ...
- LeetCode 7 Reverse Integer(反转数字)
题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...
- leetcode:Reverse Integer 及Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- LeetCode 7 Reverse Integer & int
Reverse Integer 想用余10直接算,没想到 -123%10 是 7, 原因 -123-(-123//10*10) r=a-n*[a/n] 以上,r是余数,a是被除数,n是除数. 唯一不同 ...
- 蜗牛慢慢爬 LeetCode 7. Reverse Integer [Difficulty: Easy]
题目 Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have ...
- leetcode:Reverse Integer(一个整数反序输出)
Question:Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 ...
- leetcode题解||Reverse Integer 问题
problem: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 ...
- [LeetCode][Python]Reverse Integer
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/reverse ...
- 【LeetCode】Reverse Integer(整数反转)
这道题是LeetCode里的第7道题. 题目描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 ...
随机推荐
- 高效的DDoS攻击探测与分析工具 – FastNetMon
快速使用Romanysoft LAB的技术实现 HTML 开发Mac OS App,并销售到苹果应用商店中. <HTML开发Mac OS App 视频教程> 土豆网同步更新:http: ...
- Qt在Mac OS X下的编程环境搭建(配置Qt库和编译器,有图,很清楚)
尊重作者,支持原创,如需转载,请附上原地址:http://blog.csdn.net/libaineu2004/article/details/46234079 在Mac OS X下使用Qt开发,需要 ...
- c# Lambda扩展
扩展类 public static class LinqExtensions { /// <summary> /// 创建lambda表达式:p=>true /// </sum ...
- Qt常见皮肤qss代码(有Metro的风格)
##QTabWidget 淡蓝色效果TabWidget(属性值lightblue) QTabWidget[lightblue = "true"] QTabBar::tab{ bor ...
- 【Linux】Linux下跟踪记录每个用户对主机服务器进行的操作
linux中跟踪每个用户对主机的操作,看有人之前已经写过如此shell,可直接参考,参考如下: 1.记录操作信息 这个脚本需添加至/etc/profile 脚本如下: history USER_IP= ...
- ES 20 - 查询Elasticsearch中的数据 (基于DSL查询, 包括查询校验match + bool + term)
目录 1 什么是DSL 2 DSL校验 - 定位不合法的查询语句 3 match query的使用 3.1 简单功能示例 3.1.1 查询所有文档 3.1.2 查询满足一定条件的文档 3.1.3 分页 ...
- 分享Nginx在Windows下的管理命令(bat文件)
话不多说,复制下面的内容,存成bat文件,放到nginx目录下. ====================================================@echo offrem 当前 ...
- Hive的一些学习内容
Hive相关 什么是metastore? metadata是元数据,包含数据库.表.字段.分区等信息.作用:客户端连接MetaStore服务,metastore再去连接MySQL数据库存储元数据,有了 ...
- HTTP&HTTPS
主要参考文档:<图解HTTP> HTTP简介 什么是HTTP? HTTP:(HyperText Transfer Protocol),超文本传输协议,是一个基于请求和响应,无状态的,应用层 ...
- CentOS 7出现Failed to start firewalld.service: Unit is masked的解决办法和firewalld 防火墙开关
说明:刚刚使用systemctl start firewalld命令开启防火墙的时候,却开不成功,出现Failed to start firewalld.service: Unit is masked ...