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 ...
随机推荐
- bzoj 2661: [BeiJing wc2012]连连看
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #inclu ...
- ionic build --release android
ionic bulid android ionic build --release android keytool -genkey -v -keystore demo.keystore -alias ...
- “更高效率:标准化+简约风+移动化”--K2 BPM老客户交流会
主题:工作流主数据标准化和移动工作流带来的企业沟通建设机会 嘉宾:李瑞延(盛大网络IT总监) 公司管理需要更好的工作流 -为决策提供依据 通过对各级业务公司各类流程数据的获取与分析,为管理决策提供必要 ...
- <转载>DB2常用命令
1.数据库的启动.停止 db2start --启动 db2stop [force] --停止 2.与数据库的连接.断开 db2 CONNECT TO DBName [user UserI ...
- scst使用的一些问题
1,编译问题 问题描述: [root@localhost scstadmin]# make cd scstadmin && make all ]: Entering directory ...
- JVM-内存分配与回收策略
简单介绍一下Java技术体系下的Java虚拟机内存分配与回收策略. 1.对象优先在Eden分配 大多数情况下,对象在新生代Eden区中分分配.当Eden区已没有足够空间进行分配时,虚拟机将发起一次 ...
- lightoj1082 线段树
//Accepted 5596 KB 396 ms //线段树求区间最小值 #include <cstdio> #include <cstring> #include < ...
- SecureCRT下的串口无法输入
用串口配置交换机的时候,出现的问题: 用secureCRT建了一个串口COM1后,连接上开发板后,可以正确接受和显示串口的输出,但是按键输入无效. 解决方法: Session Options -> ...
- 【转】FFMPEG 库移植到 VC 需要的步骤
原文:http://blog.csdn.net/leixiaohua1020/article/details/12747899 在VC下使用FFMPEG编译好的库,不仅仅是把.h,.lib,.dll拷 ...
- oracle 删除表和数据分析语句
TRUNCATE TABLE 表名;ANALYZE TABLE 表名 ESTIMATE STATISTICS;