当前位置:网站首页>【日常训练--腾讯精选50】7. 整数反转
【日常训练--腾讯精选50】7. 整数反转
2022-08-09 04:52:00 【Puppet__】
题目
给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果。
如果反转后整数超过 32 位的有符号整数的范围 [−231, 231 − 1] ,就返回 0。
假设环境不允许存储 64 位整数(有符号或无符号)。
示例 1:
输入:x = 123
输出:321
示例 2:
输入:x = -123
输出:-321
示例 3:
输入:x = 120
输出:21
示例 4:
输入:x = 0
输出:0
提示:
-231 <= x <= 231 - 1
代码
package tencent50;
public class leetcode7 {
// 关键在于判断是否超过区间
public 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.reverse(1534236469));
}
}
边栏推荐
- 【HMS core】【ML kit】Machine Learning Service FAQ
- 【开发者必看】【push kit】推送服务服务典型问题合集2
- 程序设计6大原则
- 【Harmony OS】【ARK UI】自定义弹窗
- 【暑期每日一题】洛谷 P5724 【深基4.习5】求极差 / 最大跨度值
- Understanding ML Cross Validation Fast
- mysql content does not exist error
- 【暑期每日一题】洛谷 P1048 [NOIP2005 普及组] 采药
- leetcode:315. 计算右侧小于当前元素的个数
- 【MLT】MLT多媒体框架生产消费架构解析(二)
猜你喜欢
LeetCode-636. 函数的独占时间
LeetCode-从链表中删去总和值为零的连续结点
[MLT] Analysis of MLT Multimedia Framework Production and Consumption Architecture (2)
How to do the stability test, this article thoroughly explains it!
LeetCode - remove consecutive nodes with a sum of zero from a linked list
2022下半年深圳信息系统项目管理师认证招生简章
抖音直播带货的4个技巧,提升直播间转化率!
杰理之播歌曲前后音量大小不一样【篇】
【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed
2022 Security Officer-B Certificate Exam Practice Questions and Online Mock Exam
随机推荐
【Harmony OS】【ARK UI】自定义弹窗
JS-DOM-全局、局部、隐式变量,数组()\函数、 prompt输入对话框、confirm(确定用户的决定-弹出对话框)
【UNR #6 A】面基之路(最短路)
ABP 6.0.0-rc.1的新特性
2022-08-08 mysql慢SQL-Q18-10GB数据量-mysql/innodb测试
杰理之电话打入,远端听不到声音【篇】
通讯录(动态版)(C语言)(VS)
【Harmony OS】【ARK UI】ETS 上下文基本操作
leetcode:316. 去除重复字母
Construction and practice of full stack code test coverage and use case discovery system
JS-全局dom对象的使用---使用htm样式和js函数动作的完全分离
Masked AutoEncoder论文及实现
LeetCode-从链表中删去总和值为零的连续结点
【HMS Core】【FAQ】【AR Engine】AR Engine FAQ
杰理之开关降噪语音识别没有用【篇】
Golang 常见知识点整理
php write online remote file to temp file
AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline'
【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed
区别如下概念:助记符、汇编语言、汇编语言程序和汇编程序。