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. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  2. [LeetCode] Bulls and Cows 公母牛游戏

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  3. vue.js学习(第一课)

    学习资料 来自台湾小凡! vue.js是javascript的一个库,只专注于UI层面,核心价值永远是 API的简洁. 第一课: 不支持IE8. 1.声明式渲染: el元素的简称 element : ...

  4. javascript关闭页面

    var browserName=navigator.appName; if (browserName=="Netscape") { window.open('','_parent' ...

  5. bzoj2243

    2243: [SDOI2011]染色 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 6753  Solved: 2496[Submit][Status ...

  6. Java学习笔记(四)

    字符串 字符串应用主要分为String类操作与字符串生成器 在程序中频繁的进行附加字符串则使用字符串生成器StringBuilder 数组 概述 数组是具有相同数据类型的一组数据的集合 数组创建 先声 ...

  7. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  8. linux下查看最消耗CPU、内存的进程

    2012-11-19 15:38:04 分类: LINUX 1.CPU占用最多的前10个进程: ps auxw|head -1;ps auxw|sort -rn -k3|head -10 2.内存消耗 ...

  9. css-css权威指南学习笔记8

    第十二章 列表与生成内容 1.list-style-type:cjk-ideographic生成一二三四的序号 2.不管是ul还是ol,list-style-type无法识别的值都应用为decimal ...

  10. 【BZOJ-2555】SubString 后缀自动机 + LinkCutTree

    2555: SubString Time Limit: 30 Sec  Memory Limit: 512 MBSubmit: 1936  Solved: 551[Submit][Status][Di ...