Reverse digits of an integer.

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

public class Solution {
public int reverse(int x) { if(x==Integer.MIN_VALUE) return 0;
long result = 0;
int i = 0; int temp = (x>0)?1:0;
x = Math.abs(x); while(x != 0){
result *= 10;
result += x%10;
x /= 10;
if(result > Integer.MAX_VALUE || result < Integer.MIN_VALUE) return 0;
}
return (temp==1)?(int)result:(int)-result; }
}

Reverse Integer LeetCode Java的更多相关文章

  1. leetcode第七题Reverse Integer (java)

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

  2. Reverse Integer [LeetCode]

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

  3. Reverse Integer ---- LeetCode 007

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

  4. Roman To Integer leetcode java

    问题描述: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range fr ...

  5. LeetCode第[7]题(Java):Reverse Integer 标签:数学

    题目:Reverse Integer 难度:Easy 题目内容: Given a 32-bit signed integer, reverse digits of an integer. Note:A ...

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

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

  7. LeetCode之Easy篇 ——(7)Reverse Integer

    7.Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: Out ...

  8. LeetCode: Reverse Integer 解题报告

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

  9. LeetCode 【2】 Reverse Integer --007

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

随机推荐

  1. Linux下yum安装MySQL

    写这篇文章的原因是:在刚开始使用Linux操作系统时想要搭建LAMP环境,于是开始在Google和百度上各种寻找资料,碰到了不是很多的问题后,我决定写这篇文章总结一下在Linux下yum安装MySQL ...

  2. [LeetCode] Valid Palindrome 验证回文字符串

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  3. jQuery Ajax传值给Servlet,在Servlet里Get接受参数乱码的解决方法

    最近在学jquery ui,在做一个小功能的时候需要将前台的值获取到,通过Ajax传递给Servlet,然后再在返回数据结果,但是在Servlet接受参数的时候,通过后台打印,发现接受乱码,代码示例如 ...

  4. C#进阶系列——一步一步封装自己的HtmlHelper组件:BootstrapHelper(三:附源码)

    前言:之前的两篇封装了一些基础的表单组件,这篇继续来封装几个基于bootstrap的其他组件.和上篇不同的是,这篇的有几个组件需要某些js文件的支持. 本文原创地址:http://www.cnblog ...

  5. 走格子 51nod

    球最少需要的能量,就是保证能量一直>=0,从头遍历取过程中能量最小值,绝对值为答案. #include<iostream> #include<algorithm> #in ...

  6. ssh key生成

    Mac电脑用终端生成SSH key 访问自己的Github 字数684 阅读427 评论4 喜欢15 前言:最近有不少刚刚使用github管理代码的开发者或者新手码农在网上 问我如何关联自己的gith ...

  7. LOL one Key

    玩英雄联盟的小伙伴们快点来,犀利的工具哦,注意一点哦,放技能的时候别按空格,不然放不出来.最后说一句这几天常说的话 新年快乐.. 下载地址:http://pan.baidu.com/s/1eQzJ8l ...

  8. BZOJ 1226: [SDOI2009]学校食堂Dining

    1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 730  Solved: 446[Submit][ ...

  9. 编译OpenCV文档

    概述 使用OpenCV的过程中经常查看文档,每次都去官网查看,不过国内访问速度很慢,有一份本地的文档就好了.本文列出了在Linux(Fedora)系统上从OpenCV源码编译出documentatio ...

  10. linux基本命令

    常用命令: w 查看登入用户(第一行为主机负载) ifconfig -a 查看所有网络 dhclient 自动获取IP地址 关机命令 init0 shutdown -h now 重启命令 init 6 ...