题目

数字翻转,即输入123,返回321;输入-123,返回-321。

代码

 class Solution {
public:
int reverse(int x) {
int result = , sign = ;
if(x < ) //负数转换为正数统一处理
{
x = -x;
sign = -;
} while(x != )
{
result *= ;
result += x % ;
x /= ;
} return result * sign; //返回时记得加上符号
}
};

LeetCode题解——Reverse Integer的更多相关文章

  1. leetcode题解||Reverse Integer 问题

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

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

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

  3. [LeetCode 题解]: Reverse Nodes in K-Groups

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Given a li ...

  4. leetcode:Reverse Integer 及Palindrome Number

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

  5. LeetCode 7 Reverse Integer & int

    Reverse Integer 想用余10直接算,没想到 -123%10 是 7, 原因 -123-(-123//10*10) r=a-n*[a/n] 以上,r是余数,a是被除数,n是除数. 唯一不同 ...

  6. Leetcode 7. Reverse Integer(水)

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

  7. leetcode:Reverse Integer(一个整数反序输出)

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

  8. [LeetCode][Python]Reverse Integer

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/reverse ...

  9. LeetCode 7. Reverse Integer(c语言版)

    题目: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123Output: 321 Ex ...

随机推荐

  1. Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)

    [题解]: 最短路径问题,保证距离最短的同时,学妹权值最大,哈哈 [code]: #include<iostream> #include<queue> #include< ...

  2. 1045: [HAOI2008] 糖果传递 - BZOJ

    Description 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1.Input 小朋友个数n 下面n行 aiOutput 求使所有人获得均等糖果的 ...

  3. 【高斯消元】Poj 1222:EXTENDED LIGHTS OUT

    Description In an extended version of the game Lights Out, is a puzzle with 5 rows of 6 buttons each ...

  4. Hibernate 二级缓存 总结整理(转)

    和<Hibernate 关系映射 收集.总结整理> 一样,本篇文章也是我很早之前收集.总结整理的,在此也发上来 希望对大家有用.因为是很早之前写的,不当之处请指正. 1.缓存:缓存是什么, ...

  5. uva 10608

    简单并查集  水水..... #include <cstdio> #include <cstring> #define maxn 30005 int fa[maxn],ans[ ...

  6. ie6 iframe src="javascript:" 报安全警报问题

    <iframe id="shuaka_iframe" class="embed-page-iframe" data-src="https://w ...

  7. Pie Charts

    Default pie chart   The default pie chart with no options set. Source Code $.plot('#placeholder', da ...

  8. C++ 嵌套类使用(一)

    一.嵌套类 在一个类的内部定义另一个类,我们称之为嵌套类(nested class),或者嵌套类型.之所以引入这样一个嵌套类,往往是因为外围类需要使用嵌套类对象作为底层实现,并且该嵌套类只用于外围类的 ...

  9. HDU2697+DP

    dp[i][j]:从前i个中挑出某些且cost不超过j的最大val. dp[i][j]:应该有1到i-1的dp[k][j-?]来更新!! /* DP dp[i][j]:从前i个中挑出某些且cost不超 ...

  10. highcharts 柱状图

    <!doctype html> <html lang="en"> <head> <script type="text/javas ...