7. Reverse Integer java
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的更多相关文章
- Reverse Integer (JAVA)
public class Solution { public int reverse(int x) { StringBuffer sb = new StringBuffer(x+"" ...
- 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 ...
- leetcode第七题Reverse Integer (java)
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, retu ...
- LeetCode第[7]题(Java):Reverse Integer 标签:数学
题目:Reverse Integer 难度:Easy 题目内容: Given a 32-bit signed integer, reverse digits of an integer. Note:A ...
- LeetCode 7 Reverse Integer(反转数字)
题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...
- Reverse Integer 2015年6月23日
题目: Reverse digits of an integer. Example1: x = , return Example2: x = -, return - 思路:递归 解答: / test ...
- Reverse Integer - 反转一个int,溢出时返回0
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- LeetCode之Easy篇 ——(7)Reverse Integer
7.Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: Out ...
- LeetCode: Reverse Integer 解题报告
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
随机推荐
- S1:new操作符
function Shape(type){ this.type = type || "rect"; this.calc = function(){ return "cal ...
- 在JavaScript 自定义对象来模拟Java中的Map
直接看代码: //模拟一个Map对象 function Map(){ //声明一个容器 var container={}; //定义一个put方法,向容器中存值 this.put=function(k ...
- IntelliJ IDEA 12.0
User name:JavaDeveloper Serial number:92547-KY2BB-QZ0S1-PEZCV-HUT8Q-6RYY4
- ODI中的临时接口
在ODI 11g及后续的版本中,针对复杂的ETL处理,可分解为多个步骤,在中间步骤中使用临时接口,而不用建立相应的物理表,ODI会在处理过程中自动创建和删除这些中间表,从而降低ETL处理复杂度:同时, ...
- 《foreach循环示例》
//foreach测试 public class ForEachTest { public static void main(String[] args) { String[] books = {&q ...
- Mysql5.0以下 手工注入
order by 20 www. .com/product/introduction.php?id=-65 UNION SELECT user(),2 www. .com/product/introd ...
- 支撑向量机(SVM)
转载自http://blog.csdn.net/passball/article/details/7661887,写的很好,虽然那人也是转了别人的做了整理(最原始文章来自http://www.blog ...
- AFNetworking vs ASIHTTPRequest vs MKNetworkKit
AFNetworking vs ASIHTTPRequest vs MKNetworkKit
- 2016-1-8 Quartz框架的学习,多个气球上升的小动画
// // BallonView.m // 气球上升的动画 // // Created by Mac on 16/1/8. // Copyright © 2016年 Mac. All rights r ...
- BZOJ 1600 建造栅栏
O(N)分成1,2与3,4两部分搞一搞. #include<iostream> #include<cstdio> #include<cstring> #includ ...