Reverse Integer

Reverse digits of an integer.

Example1: x = 123, return 321

Example2: x = -123, return -321

time=272ms accepted

public class Solution {
public int reverse(int x) {
long recv=0;
int mod=0;
int xabs=Math.abs(x);
while(xabs>0){
mod=xabs%10;
recv=recv*10+mod;
xabs/=10;
if(recv>(Math.pow(2, 31)-1))
return 0;
}
if(x<0)
recv=-recv; return (int)recv;
}
}

leetcode第七题Reverse Integer (java)的更多相关文章

  1. leetcode第七题--Reverse Integer

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

  2. 【LeetCode算法-7】Reverse Integer

    LeetCode第7题: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Outp ...

  3. LeetCode 【2】 Reverse Integer --007

    六月箴言 万物之中,希望最美:最美之物,永不凋零.—— 斯蒂芬·金 第二周算法记录 007 -- Reverse Integer (整数反转) 题干英文版: Given a 32-bit signed ...

  4. LeetCode之“数学”:Reverse Integer && Reverse Bits

    1. Reverse Integer 题目链接 题目要求: Reverse digits of an integer. Example1: x = 123, return 321 Example2:  ...

  5. Leetcode 题目整理-2 Reverse Integer && String to Integer

    今天的两道题关于基本数据类型的探讨,估计也是要考虑各种情况,要细致学习 7. Reverse Integer Reverse digits of an integer. Example1: x = 1 ...

  6. 【算法】LeetCode算法题-Reverse Integer

    这是悦乐书的第143次更新,第145篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第2题(顺位题号是7),给定32位有符号整数,然后将其反转输出.例如: 输入: 123 ...

  7. leetcode 7. Reverse Integer [java]

    public int reverse(int x) { long res = 0; while (x != 0){ res = res* 10 + x % 10; x /= 10; } if(res ...

  8. LeetCode记录之7——Reverse Integer

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

  9. leetcode第24题--Reverse Nodes in k-Group

    problem: Given a linked list, reverse the nodes of a linked list k at a time and return its modified ...

随机推荐

  1. 神奇的 BlocksKit(1):源码分析(下)

    私有类 _BKObserver _BKObserver 是用来观测属性的对象,它在接口中定义了 4 个属性: @property (nonatomic,readonly,unsafe_unretain ...

  2. iOS NSDatePicker

    1.NSDate类 1>NSDate是系统一个日期,时间类 2>就是返回当前的日期,时间 3>+(id)date; 4>返回未来secs秒后的日期,时间 5>+(id)d ...

  3. Linux Bash终端支持中文显示

    方法:修改系统变量LANG 即时生效: LANG=en_US.UTF- 永久生效: 修改.bashrc,加入 fi

  4. zzzzw_在线考试系统①准备篇

    在弄完购物系统之后,小博也了解了解怎么用struts这个框架捣鼓一个在线考试系统 购物系统用的是MVC模式,现在这个struts2原理上也是基于MVC模式的.那么要做这个东西之前先了解一下难点在哪里 ...

  5. Force removing ActivityRecord,app died, no saved state报错的理解

    为什么说理解呢?出现这个问题,我的情景是,在activity里面直接起了一个Thread,线程里面进行了一个繁重的任务,当线程执行完后,这个activity也销毁了,界面显示的任务栈下面的一个活动.百 ...

  6. c语言对于文本的基本操作

    字符读写函数  :fgetc和fputc 字符串读写函数:fgets和fputs 数据块读写函数:freed和fwrite 格式化读写函数:fscanf和fprinf   1.字符读写: fgetc函 ...

  7. 误删除了Oracle的dbf文件后的解决方法

    问题描述: 误删除Oracle数据库的dbf文件,在启动和关闭数据库是会提示错误. startup启动数据库时提示: ORA-01157:无法标识/锁定数据文件 ORA-01110:数据文件:‘... ...

  8. IOS如何刷新视图上的显示内容

    大家都知道,UItableView 有个 reloadData的方法,可以tableview刷新视图.而普通的View上面.我们如何刷新视图的呢? 下图是我做的一个用户登录之后显示用户昵称和个性签名还 ...

  9. Core Canvas–Day1

    绘制 1.坐标系统: canvas的坐标以左上角为原点,如图 可对canvas的坐标系统进行变换,变换的方式有 平移translate 旋转rotate 缩放scale 创建自定义的变换方式,切变 2 ...

  10. Mybatis-generator使用和扩展

    Mybatis-generator使用和扩展 mybatis-generator使用 pom.xml配置 <plugin> <groupId>org.mybatis.gener ...