当前位置:网站首页>7. Reverse Integer整数反转
7. Reverse Integer整数反转
2022-07-26 06:37:00 【DXB2021】
Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.
给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果。
如果反转后整数超过 32 位的有符号整数的范围 [−231, 231 − 1] ,就返回 0。
Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
假设环境不允许存储 64 位整数(有符号或无符号)。
Example 1:
Input: x = 123
Output: 321
示例 1:
输入:x = 123
输出:321
Example 2:
Input: x = -123
Output: -321
示例 2:
输入:x = -123
输出:-321
Example 3:
Input: x = 120
Output: 21
示例 3:
输入:x = 120
输出:21
示例 4:
输入:x = 0
输出:0
Constraints:提示:
-
<= x <=
- 1
C语言:
int reverse(int x){
long int r=0;
while(x)
{
if(r>INT_MAX/10||r<INT_MIN/10)
{
return 0;
}
r=r*10+x%10;
x=x/10;
}
return r;
}执行结果:通过
执行用时:4 ms, 在所有 C 提交中击败了56.33%的用户
内存消耗:5.4 MB, 在所有 C 提交中击败了71.08%的用户
通过测试用例:1032 / 1032
边栏推荐
- 深度学习——CV、CNN、RNN
- 【Web3 系列开发教程——创建你的第一个 NFT(4)】NFTs 可以给你带来什么
- Proxyman, a native high-performance packet capturing tool, is for you who love learning
- 原生高性能抓包工具Proxyman,送给爱学习的你
- Ruby on rails Code Execution Vulnerability (cve-2020-8163) technical analysis, research, judgment and protection
- SQL optimization scheme
- What is the concept and purpose of white box testing? And what are the main methods?
- Three skills are needed to engage in SAP related work
- Force buckle - 4. Find the median of two positive arrays
- Basis of multimodal semantic segmentation
猜你喜欢

Map集合继承结构

Find the original root

【图像隐藏】基于混合 DWT-HD-SVD 的数字图像水印方法技术附matlab代码

C语言进阶——可存档通讯录(文件)

Do you think you are a reliable test / development programmer? "Back to the pot"? Surface and reality

Show you the principle of IO multiplexing (select, poll and epoll)
![[nanny level] package volume optimization tutorial](/img/45/4ca66b10bb96efeb47501c07972d66.png)
[nanny level] package volume optimization tutorial

Overview of image classification of vision transformer must read series

多目标检测

Do it yourself smart home: intelligent air conditioning control
随机推荐
Slice and array of go
『HarmonyOS』探索HarmonyOS应用
Conda 虚拟环境envs目录为空
@ConstructorProperties注解理解以及其对应使用方式
【无标题】
C language introduction practice (8): switch case calculates the month, year and day of the next day (normal year / leap year calculation)
[day_020419] sort subsequence
Gdown Access denied:Cannot retrieve the public link of the file.
[day04_0421] C language multiple choice questions
Find the original root
【图像去噪】基于双立方插值和稀疏表示实现图像去噪matlab源码
Go 的通道channel
BPG notes (IV)
力扣——3. 无重复字符的最长子串
Overview of image classification of vision transformer must read series
深度学习——CV、CNN、RNN
Why the server is stuck
Map集合继承结构
Force deduction 5: Longest palindrome substring
Liberg avenue to Jane series