当前位置:网站首页>Leetcode002 -- inverts the numeric portion of a signed integer
Leetcode002 -- inverts the numeric portion of a signed integer
2022-04-23 04:39:00 【singularityDZF】
import java.util.Scanner;
public class test02 {
/**
* 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 [?2**31, 2**31? 1] , Just go back to 0.
* Suppose the environment doesn't allow storage 64 An integer ( With or without sign ).
*
* Example 1:
* Input :x = 123
* Output :321
* Example 2:
* Input :x = -123
* Output :-321
* Example 3:
* Input :x = 120
* Output :21
* Example 4:
* Input :x = 0
* Output :0
*
* Tips :
* -231 <= x <= 231 - 1
*
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print(" Please enter an integer :");
int x = sc.nextInt();
System.out.println(" After integer inversion is :"+reverse(x));
}
public static int reverse(int x){
int rev = 0;
while( x != 0 ){
if( rev > Integer.MAX_VALUE && rev <Integer.MIN_VALUE){
return 0;
}
int digit = x%10;
rev = rev*10 + digit;
x /= 10;
}
return rev;
}
}
版权声明
本文为[singularityDZF]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230438035531.html
边栏推荐
- Record your own dataset with d435i, run orbslam2 and build a dense point cloud
- leetcode009--用二分查找在数组中搜索目标值
- A heavy sword without a blade is a great skill
- 数据孤岛是什么?为什么2022年仍然存在数据孤岛?
- QML advanced (IV) - drawing custom controls
- Huawei machine test -- high precision integer addition
- 从MySQL数据库迁移到AWS DynamoDB
- A lifetime of needs, team collaboration can play this way on cloud nailing applet
- shell wc (统计字符数量)的基本使用
- 基于英飞凌MCU GTM模块的无刷电机驱动方案开源啦
猜你喜欢
Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
指纹Key全国产化电子元件推荐方案
[paper reading] [3D target detection] point transformer
win10, mysql-8.0.26-winx64. Zip installation
STM32 MCU ADC rule group multi-channel conversion DMA mode
Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases
IDE idea automatic compilation and configuration of on update action and on frame deactivation
The perfect combination of collaborative process and multi process
STM32 upper μ C / shell transplantation and Application
test
随机推荐
leetcode002--将有符号整数的数字部分反转
IDE Idea 自动编译 与 On Upate Action 、 On Frame Deactivation 的配置
Iron and intestinal flora
AWS EKS添加集群用户或IAM角色
【Pytorch基础】torch.split()用法
从MySQL数据库迁移到AWS DynamoDB
MySQL queries users logged in for at least N consecutive days
Nature medicine reveals individual risk factors of coronary artery disease
Improving 3D object detection with channel wise transformer
What is the thirty-six plan
【Echart】echart 入門
383. Ransom letter
520. Detect capital letters
mysql table 中增加列的SQL语句
C语言: 指针的进阶
Set classic topics
Jetpack 之 LifeCycle 组件使用详解
Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
Use recyclerview to realize left-right side-by-side classification selection
数据孤岛是什么?为什么2022年仍然存在数据孤岛?