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. S1:new操作符

    function Shape(type){ this.type = type || "rect"; this.calc = function(){ return "cal ...

  2. 在JavaScript 自定义对象来模拟Java中的Map

    直接看代码: //模拟一个Map对象 function Map(){ //声明一个容器 var container={}; //定义一个put方法,向容器中存值 this.put=function(k ...

  3. IntelliJ IDEA 12.0

    User name:JavaDeveloper Serial number:92547-KY2BB-QZ0S1-PEZCV-HUT8Q-6RYY4

  4. ODI中的临时接口

    在ODI 11g及后续的版本中,针对复杂的ETL处理,可分解为多个步骤,在中间步骤中使用临时接口,而不用建立相应的物理表,ODI会在处理过程中自动创建和删除这些中间表,从而降低ETL处理复杂度:同时, ...

  5. 《foreach循环示例》

    //foreach测试 public class ForEachTest { public static void main(String[] args) { String[] books = {&q ...

  6. Mysql5.0以下 手工注入

    order by 20 www. .com/product/introduction.php?id=-65 UNION SELECT user(),2 www. .com/product/introd ...

  7. 支撑向量机(SVM)

    转载自http://blog.csdn.net/passball/article/details/7661887,写的很好,虽然那人也是转了别人的做了整理(最原始文章来自http://www.blog ...

  8. AFNetworking vs ASIHTTPRequest vs MKNetworkKit

    AFNetworking vs ASIHTTPRequest vs MKNetworkKit

  9. 2016-1-8 Quartz框架的学习,多个气球上升的小动画

    // // BallonView.m // 气球上升的动画 // // Created by Mac on 16/1/8. // Copyright © 2016年 Mac. All rights r ...

  10. BZOJ 1600 建造栅栏

    O(N)分成1,2与3,4两部分搞一搞. #include<iostream> #include<cstdio> #include<cstring> #includ ...