当前位置:网站首页>7. Reverse integer integer
7. Reverse integer integer
2022-07-26 06:43: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.
To give you one 32 Signed integer of bit x , Return to x The result of reversing the number part in .
If the integer after inversion exceeds 32 The range of signed integers of bits [−231, 231 − 1] , Just go back to 0.
Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
Suppose the environment doesn't allow storage 64 An integer ( With or without sign ).
Example 1:
Input: x = 123
Output: 321
Example 1:
Input :x = 123
Output :321
Example 2:
Input: x = -123
Output: -321
Example 2:
Input :x = -123
Output :-321
Example 3:
Input: x = 120
Output: 21
Example 3:
Input :x = 120
Output :21
Example 4:
Input :x = 0
Output :0
Constraints: Tips :
-
<= x <=
- 1
C Language :
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;
}Execution results : adopt
Execution time :4 ms, In all C Defeated in submission 56.33% Users of
Memory consumption :5.4 MB, In all C Defeated in submission 71.08% Users of
Pass the test case :1032 / 1032
边栏推荐
猜你喜欢

Proxyman, a native high-performance packet capturing tool, is for you who love learning

How does the seckill system ensure that the database does not crash and prevent oversold goods

Facing the rebound market, how do we operate? 2020-03-21

mysql优化之show profile的使用及分析

CONDA virtual environment envs directory is empty

Torth file read vulnerability (cnvd-2020-27769)

曲线曲率展示

『HarmonyOS』工程的创建与虚拟机的使用

Experimental flags: --disable_ admission_ control=false --enable_ rm=false --llama_ callback_ port=28000

【图像隐藏】基于混合 DWT-HD-SVD 的数字图像水印方法技术附matlab代码
随机推荐
C language file operation
抖音web端 s_v_web_id 参数生成分析与实现
Decomposing a positive integer into prime factors requires decomposing into as many factors as possible.
III Actual combat - current time representation and world standard time format
【Star项目】小帽飞机大战(二)
Go channel
【C语言】文件操作
MySQL基础篇(二)-- MySQL 基础
Vision Transformer 必读系列之图像分类综述
Database and the future of open source
Proxyman, a native high-performance packet capturing tool, is for you who love learning
【Star项目】小帽飞机大战(三)
Quick sort
PMP customs formula, don't hurry to recite it
Find the original root
Multi target detection
7. Reverse Integer整数反转
『牛客|每日一题』有效括号序列
[pytorch] picture enlargement
JVM class loading and GC garbage collection mechanism