[Lintcode] #413 反转整数
来源:互联网 发布:百万淘宝客程序 编辑:程序博客网 时间:2024/05/24 03:24
将一个整数中的数字进行颠倒,当颠倒后的整数溢出时,返回 0 (标记为 32 位整数)。
样例
给定 x = 123
,返回 321
给定 x = -123
,返回 -321
public class Solution { /* * @param n: the integer to be reversed * @return: the reversed integer */ public int reverseInteger(int n) { // write your code here long re = 0;int flag = n > 0 ? 1 : -1;n = Math.abs(n);while (n > 0) {int cur = n % 10;n /= 10;re = re * 10 + cur;}if (re > Integer.MAX_VALUE)return 0;elsereturn (int) re * flag; }}
阅读全文
0 0
- [Lintcode] #413 反转整数
- LintCode 第413题 反转整数 【整数】
- lintcode ----反转整数
- lintcode,反转整数
- Lintcode 反转整数
- LintCode - 413.反转整数
- LintCode之反转整数
- 【LintCode】反转整数
- lintcode反转整数
- Lintcode反转整数
- [LintCode]413.反转整数
- 反转整数-LintCode
- LintCode python 小白-简单题-413-反转整数
- 413-反转整数
- 反转整数
- 反转整数
- 反转整数
- 整数反转
- Webstrom--chrome debug调试配置教程
- GetLastError()返回值列表
- idea 如何将项目导出为war
- coordinatorlayout和behavior解析
- Django的admin配置
- [Lintcode] #413 反转整数
- 服务器端I / O性能:Node,PHP,Java与Go
- Hibernate小问题
- IPSG简介
- 职业规划
- C# 调用C++ DLL 的类型转换
- html页面集成markdown编辑器
- Android studio下Cmake配置编译开发jni总结
- APICloud的学习成长之路(一)