Reverse digits of an integer.

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

代码如下:

public class Solution {
public int reverse(int n) {
long sum=0;
int flag=1; if(n<0)
{
flag=-1;
n=n*(-1);
}
try{
String s=Integer.toString(n);
s=new StringBuffer(s).reverse().toString();
sum=Integer.valueOf(s)*flag;
}catch(NumberFormatException e)
{return 0;} return (int)sum;
}
}

7. Reverse Integer java的更多相关文章

  1. Reverse Integer (JAVA)

    public class Solution { public int reverse(int x) { StringBuffer sb = new StringBuffer(x+"" ...

  2. 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 ...

  3. leetcode第七题Reverse Integer (java)

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

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

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

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

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

  6. Reverse Integer 2015年6月23日

    题目: Reverse digits of an integer. Example1: x = , return Example2: x = -, return - 思路:递归 解答: / test ...

  7. Reverse Integer - 反转一个int,溢出时返回0

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

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

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

  9. LeetCode: Reverse Integer 解题报告

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

随机推荐

  1. 再谈IT行业工程师文化

    为什么是再呢?因为“工程师文化”这种说法网上很多,各种理解,各种版 本,我只是简单说说我的认识,说的不对的地方敬请各位大牛,高手,高高手多多指教,我本身也是个技术人员,不过只是技术不怎么样而已.写这个 ...

  2. VS2010连接SQLite数据库

    Visual studio 2010及以上版本,连接SQLite数据库 1.在Sqlite开发站点下载SQLite的.exe安装包 Ctrl+F搜索这条语句:This is the only setu ...

  3. POJ 3525 半平面交+二分

    二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点 #include <cstdio> #include <cstring> # ...

  4. 获取Android系统的版本号

    int currentVersion = android.os.Build.VERSION.SDK_INT;

  5. 解决python version 2.7 required,which was not find in the registry

    程序自动写注册表 http://www.vvivv.com/post-143.html 手工写 http://blog.csdn.net/baikaishui525/article/details/9 ...

  6. CCNA 4.14 TP Correction

    All people seem to need data processing ( Application presentation session transport network data li ...

  7. JAVA工作方式

    public class Hellow { int eyes = 2; int ears = 2; int legs = 4; void run(){ //方法 System.out.println( ...

  8. IOS开发中--点击imageView上的Button没有任何反应

    点击imageView上的Button没有任何反应:    解决方法:设置图片的userInteractionEnabled为YES,使该imageView可以与用户进行交互

  9. c# Winforms WebBrowser - Clear all cookies

    Hello,   I recently search for a method to delete all cookies from the build in .NET WinForms WebBro ...

  10. 安装xampp后,遇到的各种问题

    一.apache无法启动 1.查看端口是否被占用 80端口冲突,解决方法:打开目录C:\xampp\apache\conf(我的安装目录为C:\xampp)下的httpd.conf文件,将Listen ...