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. linux 打补丁 2原理

    1.创建目录 demo cd demo 有bug文件a.txt: 当前目录为demo mkdir -p old/a/p vi old/a/p/foo.txt old_line_1 old_line_2 ...

  2. 【转】如何高效利用GitHub——2013-08-28 22

    http://www.yangzhiping.com/tech/github.html  正是Github,让社会化编程成为现实.本文尝试谈谈GitHub的文化.技巧与影响. Q1:GitHub是什么 ...

  3. The Tangled Web (Web之困)第四章 摘要

    1. HTML语法: 由Tag组成层级结构,标签视为名,而值插在当中. 关键组成符:<, >, ', ", & 2. 解析模式: 文件开头<!DOCTYPE> ...

  4. 关于ProgressBar的美化问题

    Android自带的ProgressBar其实也算不上丑陋,但是如果所有的App都使用一个模式的ProgressBar,那么估计用户就要崩溃了,打开任何一个App,擦,进度条都一模一样..有鉴于此,我 ...

  5. 解析XML文件时做得修改

    在.h文件中找到需要在Build Settings中设置的东西,查找Header Search Paths,然后添加/usr/include/libxml2

  6. create---创建表

    create table table_name (列名 数据类型 是否非空 约束信息, 列名 数据类型 是否非空 约束信息, 列名 数据类型 是否非空 约束信息, ........); 例: crea ...

  7. Linux常用系统调用

    转载 http://www.ibm.com/developerworks/cn/linux/kernel/syscall/part1/appendix.html#icomments 按照惯例,这个列表 ...

  8. 16Aspx.com源码2014年7月详细

            Web电子商务网(三层)V2.0源码 2014-07-31   [VS2010] 源码介绍: Web电子商务网(三层)V2.0源码 源码描述: 一.源码特点     采用三层架构开发, ...

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

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

  10. LigerUI API

    参数列表 参数名 类型 描述 默认值 title String 表格标题 null width String|Int 宽度值,支持百分比 'auto' height String|Int 高度值,支持 ...