LeetCode 7 Reverse Integer int:2147483647-2147483648 难度:2
https://leetcode.com/problems/reverse-integer/
class Solution {
public:
int inf = ~0u >> 1;
int reverse(int x) {
if(x == 0)return 0;
long long tx = x;
long long ans = 0;
for(int i = 0;tx;i++){
ans = ans * 10 + tx % 10;
tx /= 10;
}
return int(ans) == ans?ans:0;
}
};
LeetCode 7 Reverse Integer int:2147483647-2147483648 难度:2的更多相关文章
- 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(反转数字)
题目来源: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(水)
7. Reverse Integer Easy Given a 32-bit signed integer, reverse digits of an integer. Example 1: Inpu ...
- [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 ...
- [LeetCode] 7. Reverse Integer 翻转整数
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...
- Java [leetcode 7] Reverse Integer
问题描述: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Ha ...
- [LeetCode] 7. Reverse Integer ☆
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have y ...
随机推荐
- 关于ř与画面的集成---- k均值聚类
1.利用R内置数据集iris: 2.通过Rserve 包连接tableau,服务器:localhost,默认端口6311: 3.加载数据集iris: 4.编辑字段:Cluster <span s ...
- mysql GROUP_CONCAT+ GROUP BY + substring_index获取分组的前几名
mysql方法来源于:http://www.cnblogs.com/jjcc/p/5896588.html ###在网上看到一篇,非常赞的方法### 比如说要获取班级的前3名,mysql就可以用GRO ...
- 微信小程序-发起请求
wx.request(object) wx.request发起的是https请求.一个微信小程序,同时只能有5个网络请求连接. object参数说明: 示例代码: wx.request({ url: ...
- EF CodeFirst 关系配置
自从开始学习asp.net mvc采用code first以来,关系配置就没有搞清楚过!(⊙﹏⊙)b 笔记之前先感谢以下文章和博主,对他们表示崇拜,由浅入深.举例恰当.拨云见日.茅塞顿开,还有什么词, ...
- less简单用法
http://less.bootcss.comless工具:koala工具url:http://koala-app.com/index-zh.html// less import: // less 文 ...
- for循环j = j++ 和 j = ++j
package com.test.forname; public class TestForName { public static void main(String[] args) throws E ...
- hihoCoder 1425 : What a Beautiful Lake(美丽滴湖)
hihoCoder #1425 : What a Beautiful Lake(美丽滴湖) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 ...
- img的空白符
在div里面嵌套了一个img出来问题,div的高度超过了img的高度,大约3px ,查看了样式没什么问题,后来百度了一下,找到了2种的方法都有效: 第一种:img{display:block} 第二种 ...
- Linux 系统时间和硬件时间
linux 的系统时间有时跟硬件时间是不同步的 Linux时钟分为系统时钟(System Clock)和硬件(Real Time Clock,简称RTC)时钟.系统时钟是指当前Linux Kernel ...
- 【转载】js 各种复制到剪贴板
一.实现点击按钮,复制文本框中的的内容 <script type="text/javascript"> function ...