当前位置:网站首页>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
边栏推荐
- Press in and pop-up sequence of "Niuke | daily question" stack
- 原生高性能抓包工具Proxyman,送给爱学习的你
- 输入5个学生的记录(每条记录包括学号和成绩), 组成记录数组, 然后按照成绩由高到低的次序输出. 排序方法采用选择排序
- Is there any online account opening process of Huatai Securities? Is online account opening safe
- CS5801_HDMI转EDP优势替代LT6711A方案
- 【Star项目】小帽飞机大战(二)
- [image hiding] digital image watermarking method technology based on hybrid dwt-hd-svd with matlab code
- 数据库中varchar和Nvarchar区别与联系
- 7. Reverse Integer整数反转
- 定义方法时为什么使用static关键字
猜你喜欢

XSS-labs(1-10)闯关详解

Show you the principle of IO multiplexing (select, poll and epoll)

【毕业季_进击的技术er】送别过去两年迷茫的自己。重整旗鼓,大三我来啦

『牛客|每日一题』逆波兰表达式

C language file operation

堆排序(heap-sort)

【Web3 系列开发教程——创建你的第一个 NFT(4)】NFTs 可以给你带来什么

Deep learning - CV, CNN, RNN

What is the concept and purpose of white box testing? And what are the main methods?
![[untitled]](/img/42/5e8b62edc0aa289098425b26df2453.jpg)
[untitled]
随机推荐
What are the main reasons for server crash
源代码加密技术发展阶段
Why use the static keyword when defining methods
shell编程
快速排序(quick-sort)
【保姆级】包体积优化教程
【毕业季_进击的技术er】送别过去两年迷茫的自己。重整旗鼓,大三我来啦
III Actual combat - current time representation and world standard time format
Map dictionary and constraints of go
C language introduction practice (8): switch case calculates the month, year and day of the next day (normal year / leap year calculation)
『牛客|每日一题』 栈的压入、弹出序列
Vim中删除^M
20000 words will take you from 0 to 1 to build an enterprise level microservice security framework
Curve curvature display
服装行业如何实现数字化生产模式
Experimental flags: --disable_ admission_ control=false --enable_ rm=false --llama_ callback_ port=28000
[1] Basic knowledge of mathematical modeling
Use and analysis of show profile optimized by MySQL
Show you the principle of IO multiplexing (select, poll and epoll)
堆排序(heap-sort)