当前位置:网站首页>[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));}}
边栏推荐
猜你喜欢
MySQL: Implementation Principles of Submitted Read and Repeatable Read | MVCC (Multi-Version Concurrency Control) - Notes for Your Own Use
JS-DOM-对象的事件onload、匿名函数、this
Pycharm社区版专业版下载安装环境配置【精细到每一个步骤】
杰理之电话打入,远端听不到声音【篇】
安装pytorch和cuda
2022年8月深圳产品经理认证招生简章(NPDP)
Zuul---路由功能
杰理之智能充电仓低电发码关机 触摸不开机【篇】
[Harmony OS] [ArkUI] ets development graphics and animation drawing
杰理之手机OTG问题【篇】
随机推荐
如何剪裁svg并压缩
抖音直播带货的4个技巧,提升直播间转化率!
【Harmony OS】【ArkUI】ets开发 图形与动画绘制
无法通过头文件中的宏定义或全局变量修改动态库中的参数
[MLT] Analysis of MLT Multimedia Framework Production and Consumption Architecture (2)
【暑期每日一题】洛谷 P5729 【深基5.例7】工艺品制作
抖音直播间带货最新玩法和运营技巧
杰理之播放最大音量提示音播不出来【篇】
EDI对接 New York & Company案例
杰理之电话打入,远端听不到声音【篇】
JS-全局dom对象的使用---使用htm样式和js函数动作的完全分离
【暑期每日一题】洛谷 P1216 [USACO1.5][IOI1994]数字三角形 Number Triangles
说明高级语言、汇编语言、机器语言三者的区别,谈谈你对汇编语言的认识。
Alibaba Cloud Tianchi Contest Question (Machine Learning) - Prediction of Industrial Steam Volume (Complete Code)
通讯录(动态版)(C语言)(VS)
换座位[异或巧妙的让奇偶互换]
Ali YunTianChi competition problem (deep learning) - video enhancement (complete code)
Understanding ML Cross Validation Fast
leetcode:402. 移掉 K 位数字
【HMS Core】【FAQ】【AR Engine】AR Engine FAQ