知识点:

  • 内置变量 INT_MAX   INT_MIN
  • 运算结果是否溢出的判断
    • 判断pop>7即pop>INT_MAX%10
    • 判断pop<-8即pop<INT_MIN%10
  • class Solution {
    public:
    int reverse(int x) {
    int pop,ans=;
    while(x)
    {
    pop = x%;
    x /= ;
    if(ans > INT_MAX/ || (ans == INT_MAX/ && pop >))
    return ;
    if(ans < INT_MIN/ || (ans == INT_MIN/ && pop <-))
    return ;
    //cout << "pop: " << pop << " ans: " << ans << '\n';
    ans = ans* + pop;
    }
    return ans;
    }
    };

7. 反转整数(Reverse Integer) C++的更多相关文章

  1. [Swift]LeetCode7. 反转整数 | Reverse Integer

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

  2. Leetcode 7 反转整数Reverse Integer

    给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321  示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 注意: ...

  3. LeetCode 7. 反转整数(Reverse Integer)

    题目描述 给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321  示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 ...

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

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

  5. Reverse Integer - 反转一个int,溢出时返回0

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

  6. [LintCode] Reverse Integer 翻转整数

    Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). ...

  7. leetCode(62)-Reverse Integer

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

  8. 【算法】LeetCode算法题-Reverse Integer

    这是悦乐书的第143次更新,第145篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第2题(顺位题号是7),给定32位有符号整数,然后将其反转输出.例如: 输入: 123 ...

  9. leetcode:Reverse Integer 及Palindrome Number

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

随机推荐

  1. python运维小技巧

    以下实验均在Linux上进行 1.一秒钟启动一个下载服务器 python版本 python2:  #python -m SimpleHTTPServer Serving HTTP on 0.0.0.0 ...

  2. super()、this属性与static静态方法的执行逻辑

    1.super的构造顺序:永远优先构造父类的方法 2.static永远在类实例之前执行,this的使用范围为实例之后

  3. JQ遇到$(‘.xxx’).attr(‘display’)一直返回undefined

    jq attr && jq css 1.1 attr() 方法设置或返回被选元素的属性值 我们就题目遇到的问题做一个测试 //html <div class="div1 ...

  4. go helloworld

    // Sample program to show how a bytes.Buffer can also be used // with the io.Copy function. package ...

  5. [osg][原]osg的坐标系:使用右手法则Y轴向前、X向、右Z向上。camare的默认姿态:向下看(Z轴负向),头向前(Y轴正向)

    参考:http://blog.csdn.net/tmljs1988/article/details/7561887 图中上半边为opengl坐标系,下半边的osg坐标系: osg::Camare的默认 ...

  6. python3.5学习第一章

    在python中,变量赋值或者其他语句后不需要加”:“ python中,缩进特别重要! 条件语句和循环语句,要加”:“ 一.变量赋值 name = "cecelia"name2 = ...

  7. cordova + Vue 开发 APP 上手指南

    什么是 cordova cordova 是由 Apache 基金会支持的,使用 HTML5 + CSS3 + JS 来构建多平台 APP 程序的开发框架.其支持调用手机系统(Android.IOS.W ...

  8. Semana i 2018

    Semana i 2018 A Giga-Kilo-Gigabyte 思路: dp水题 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pra ...

  9. Visual Studio 2015+InstallShield 2015

    下载Installshield http://learn.flexerasoftware.com/content/IS-EVAL-InstallShield-Limited-Edition-Visua ...

  10. pdf can't copy text 无法复制文字

    有些 pdf 是通过图片弄出来的,或者被 protect 了. 我们会无法 copy 里面的字. 这个时候可以用 OCR (Optical character recognition) 就是从图片中识 ...