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. 【转】C++里定义全局变量和函数常用方法

    http://blog.csdn.net/niying/article/details/637084 1:在头文件是声明变量,然后在使用的文件中用exten标识. ".h": in ...

  2. <video>和<audio>标签

    一.<video>基本格式: <video width=" " heigh="" src=""> </vide ...

  3. Integer跟int的区别(备份回忆)

    int与Integer的区别 int 是基本数据类型Integer是其包装类,注意是一个类.为什么要提供包装类呢???一是为了在各种类型间转化,通过各种方法的调用.否则 你无法直接通过变量转化.比如, ...

  4. Java集合和PHP的对比

    这里突然感觉到在java中的集合,和php的数组非常相似 .

  5. Sql触发器脚本

    ALTER Trigger [dbo].[test] --新建触发器 On [dbo].[test1] --在test1表中创建触发器 for insert --触发条件 As --事件触发后所要做的 ...

  6. 不需要软件让Windows7变身WIFI热点

    很简单,就是把一台装有windows 7操作系统,并配有无线网卡的电脑变成一台无线路由器或无线AP,以便在没有路由器的环境中实现多台无线终端(比如支持wifi的手机.电脑等设备)共享无线网络.那么我们 ...

  7. Unity 3D 文件导入出错误解决方法以及unity圣典离线版下载地址

    1.安装unity 时我选择了free版的,打开已有项目时出现如下错误提示. 解决方法:先把要导入的文件先拷贝到unity3d安装目录下对应的文件夹内,之后再返回unity3d软件,右键选择“导入”. ...

  8. (一)问候Hibernate4

    第一节:Hibernate 简介 官网:http://hibernate.org/ Hibernate 是一个开放源代码的对象关系映射框架,它对JDBC 进行了非常轻量级的对象封装,使得Java程序员 ...

  9. O-C相关-07-@property关键字简介与使用

    基本概念:在O-C中,创建完类之后还需要给一个类添加属性和方法,之前说过的set和get方法比较繁琐,因此引入了@property 这个编译器指令.@property 是一个编译器指令.所谓的编译器指 ...

  10. LA 3516(ZOJ 2641) Exploring Pyramids(递推 DP)

    Exploring Pyramids Archaeologists have discovered a new set of hidden caves in one of the Egyptian p ...