问题描述

Example1: x = 123, return 321
Example2: x = -123, return -321

原题链接: https://leetcode.com/problems/reverse-integer/

解决方案

 public int reverse(int x) {
long res = 0; //need to consider the overflow problem
while(x != 0){
res = res * 10 + x % 10; // -11%10 = -1
if(res > Integer.MAX_VALUE || res < Integer.MIN_VALUE){
return 0;
}
x = x/10;
}
return (int)res;
}

Leetcode7 : Reverse Integer 整数反转问题的更多相关文章

  1. 【LeetCode】Reverse Integer(整数反转)

    这道题是LeetCode里的第7道题. 题目描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321  示例 2: 输入: -123 ...

  2. 【LeetCode】7. Reverse Integer 整数反转

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:整数,反转,题解,Leetcode, 力扣,Python, ...

  3. [LeetCode]7. Reverse Integer整数反转

    Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...

  4. LeetCode 7 Reverse Integer(反转数字)

    题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...

  5. LeetCode7:Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...

  6. 7 Reverse Integer(数字反转Easy)

    题目意思:int数字反转 考虑:越界问题 class Solution { public: int reverse(int x) { ; while(x){ ans=ans*+x%; x=x/; } ...

  7. 7. Reverse Integer (整数的溢出)

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 For the p ...

  8. [Leetcode] reverse integer 反转整数

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...

  9. leetcode:Reverse Integer(一个整数反序输出)

    Question:Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 ...

随机推荐

  1. JS前端将table导出到excel 兼容谷歌 IE 且保留表格样式

    CDSN上博主给我一段代码,可将表格导出为EXCEL文档,原文见: https://blog.csdn.net/zz210891470/article/details/94717644 向博主学习.致 ...

  2. 不用任何第三方,写一个RTMP直播推流器

    2016年是移动直播爆发年,不到半年的时间内无数移动直播App掀起了全民直播的热潮.然而个人觉得直播的门槛相对较高,从推流端到服务端器到播放端,无不需要专业的技术来支撑,仅仅推流端就有不少需要学习的知 ...

  3. Spring Cloud Hoxton正式发布,Spring Boot 2.2 不再孤单

    距离Spring Boot 2.2.0的发布已经有一个半月左右时间,由于与之匹配的Spring Cloud版本一直没有Release,所以在这期间碰到不少读者咨询的问题都是由于Spring Boot和 ...

  4. iOS13暂时关闭黑暗模式+应用内状态栏无法显示问题解决办法

    现象: iOS13黑暗模式开启后,app显示会出现很多意外显示情况.暂时屏蔽是最好的选择.当开启黑暗模式,且在项目的target对应的info.plist中添加以下设置时(禁用黑暗模式): <k ...

  5. SpringBoot添加热部署

    一.导入依赖 <!--热部署--> <dependency> <groupId>org.springframework.boot</groupId> & ...

  6. Java修炼——冒泡排序

    核心思想: 1)如有一个数列有 N(5)个元素,则至多需要 N-1(4)趟循环 才能保证数列有序 2) 每一趟循环都从数列的第一个元素开始比较,依次比较 相邻的两个元素,比较到数列的最后 3) 如果前 ...

  7. 【重温基础】16.JSON对象介绍

    本文是 重温基础 系列文章的第十六篇. 今日感受:静. 系列目录: [复习资料]ES6/ES7/ES8/ES9资料整理(个人整理) [重温基础]1-14篇 [重温基础]15.JS对象介绍 本章节复习的 ...

  8. Spring-security-oAuth2分享

    Spring-security-oAuth2分享 oAuth2简介 OAuth 2.0是用于授权的行业标准协议.OAuth 2.0致力于简化客户端开发人员的工作,同时为Web应用程序,桌面应用程序,移 ...

  9. 001_Java概述与环境搭建

    Java由来: SUN公司开发,95年推出,96年推出JDK1.0版本 09年被Oracle(甲骨文)收购 詹姆斯·高斯林被称作“Java之父” JavaSE:Java Standard Editoi ...

  10. docker入门-安装篇

    一.docker介绍 1:docker官网 www.docker.com 2:github  https://github.com/docker/docker.github.io 3:开源的容器引擎, ...