问题描述

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. MySQL CRUD使用之小总结

    总结一下最近碰到的一些关于MySQL CRUD方面的语句. 在使用pymysql的executemany方法时,需要注意的几个问题: 1.在写sql语句时,不管字段为什么类型,占位符统一使用%s,且不 ...

  2. Vue引入

    Vue引入 概念: 1.el:实例 new Vue({ el: '#app' }) // 实例与页面挂载点一一对应 // 一个页面中可以出现多个实例对应多个挂载点 // 实例只操作挂载点内部内容 2. ...

  3. c# 窗体开发2 高级控件的使用

    1.单选按钮(RadioButton) 同一组中其他单选按钮不能同时选定 分组形式:panel GoupBox 窗体 方法: 属性 说明 Appearance RadioButton 控件的显示与命令 ...

  4. Android Activity生命周期及启动模式

    曾经搞过许多东西,再熟练的东西一段时间没有碰都会生疏或忘记.后来体会到写成文档记录下来的重要性,但有些word或ppt记录下来的东西随着时间流逝会丢失,或者不愿去看.或许保存成博客的形式,会是更好的选 ...

  5. Sql Server连表查询字段为null

    这是一个坑,并且是有毒的坑. 一不小心我就掉进了这个坑里面,费了好大的力气这才从坑里面爬出来. 话不多说,开始吹BB啦. 一.简单说说遇到的问题: 连表查询,一对多. 出现 int,  smallda ...

  6. [NACOS HTTP-GET] The maximum number of tolerable server reconnection errors has been reached

    错误的意思是:已达到可容忍的服务器重连接错误的最大数目.有两个解决思路:一个将这个值设置的更大:然后是排查自己连接服务哪儿出了问题.先说在哪儿设置这个值:在拉取nacos服务的注解配置中,添加一个属性 ...

  7. use dict in bash

    declare -A animals=(["moo"]="cow" ["woof"]="dog") for sound ...

  8. 求亿级记录中搜索次数Top N的搜索词(MapReduce实现)

    程序事例: 日志信息: 二手车 1345 二手房 3416 洗衣机 2789 输入: N=2 输出: 二手房 洗衣机 map函数如下: import java.io.IOException; impo ...

  9. elasticSerach 知识学习

    一 介绍: ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearch是用Java语言开发的, ...

  10. 使用Fiddler 对ios 设备进行HTTPS 的抓取

    http://blog.csdn.net/skylin19840101/article/details/43485911  使用Fiddler 对ios 设备进行HTTPS 的抓取