当前位置:网站首页>[Daily Training--Tencent Featured 50] 7. Integer Reversal
[Daily Training--Tencent Featured 50] 7. Integer Reversal
2022-08-09 04:53:00 【Puppet__】
Title
Given a 32-bit signed integer x , return the result of inverting the numeric part of x .
Returns 0 if the inverted integer exceeds the range of 32-bit signed integers [−231, 231 − 1] .
Assume that the environment does not allow storage of 64-bit integers (signed or unsigned).
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
Hint:
-231<= x <= 231 - 1
Code
package tencent50;public class leetcode7 {// The key is to judge whether it exceeds the intervalpublic int reverse(int x) {long ans = 0;while (x != 0){ans = ans * 10 + x % 10;x /= 10;}return ans==(int)ans ? (int) ans : 0;}public static void main(String[] args) {leetcode7 obj = new leetcode7();System.out.println(obj.reversespan>(1534236469));}}
边栏推荐
- Base64编码和图片转化
- 【Harmony OS】【ArkUI】ets开发 创建视图与构建布局
- 【Harmony OS】【ARK UI】Custom popup
- A case of missing heritability
- 软件测试的方法详细介绍
- TASSEL software imports plink format file error
- HP路由器和交换机日志分析
- FastDFS快速使用及介绍
- MySQL: Intent Shared Locks and Intentional Exclusive Locks | Deadlocks | Lock Optimization
- 【Harmony OS】【ArkUI】ets开发 图形与动画绘制
猜你喜欢
TCP/IP协议中分包与重组原理介绍、分片偏移量的计算方法、IPv4报文格式
Alibaba Cloud Tianchi Contest Question (Machine Learning) - Prediction of Industrial Steam Volume (Complete Code)
浙江DAMA-CDGA/CDGP数据治理认证招生简章
[Harmony OS] [ARK UI] ETS context basic operations
杰理之开关降噪语音识别没有用【篇】
JS-DOM-对象的事件onload、匿名函数、this
LN论文、五种归一化原理和实现
数据库设计---三范式和反范式设计
C进阶 - 程序的编译(预处理操作) + 链接
杰理之SD卡切回蓝牙没有作用【篇】
随机推荐
pytorch implementation of Poly1CrossEntropyLoss
数据库事务&锁机制
软件测试的方法详细介绍
php使用phpoffice/phpspreadsheet导入导出excel表格
【Harmony OS】【ARK UI】公共事件模块
杰理之开关降噪语音识别没有用【篇】
【luogu U142356】Suffix of the Brave (SA) (Chairman Tree) (2 points)
dsafasfdasfasf
换座位[异或巧妙的让奇偶互换]
ddr系统检验
pr22.5最新版下载地址
FastDFS快速使用及介绍
【暑期每日一题】洛谷 P4325 [COCI2006-2007#1] Modulo
区别如下概念:路径、绝对路径、相对路径、当前目录。系统磁盘上存在某个可执行文件,但在DOS环境输入其文件名却提示没有这个文件,是什么原因?
Integer multiple series
TCP/IP协议中分包与重组原理介绍、分片偏移量的计算方法、IPv4报文格式
I.MX6U-ALPHA开发板(串口实验)
程序设计6大原则
JS-全局dom对象的使用---使用htm样式和js函数动作的完全分离
如何剪裁svg并压缩