7. Reverse Integer

Problem's Link

----------------------------------------------------------------------------

Mean:

将一个整数的数值位反转.

analyse:

题目没说当精度溢出时返回0.这个地方要注意一下.

Time complexity: O(N)

view code

/**
* -----------------------------------------------------------------
* Copyright (c) 2016 crazyacking.All rights reserved.
* -----------------------------------------------------------------
*       Author: crazyacking
*       Date  : 2016-02-15-15.08
*/
#include <queue>
#include <cstdio>
#include <set>
#include <string>
#include <stack>
#include <cmath>
#include <climits>
#include <map>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long(LL);
typedef unsigned long long(ULL);
const double eps(1e-8);

class Solution
{
public:
   int reverse(int x)
   {
       bool isNeg(x<0?1:0);
       int64_t xx;
       if(x<0) xx=-1*(int64_t)x;
       else xx=(int64_t)x;
       int64_t ret=0;
       while(xx)
       {
           int tmp=xx%10;
           xx/=10;
           ret=ret*10+tmp;
       }
       if(ret>INT_MAX)
           return 0;
       if(isNeg)
           ret=-ret;
       return ret;
   }
};

int main()
{
   cout<<LLONG_MAX<<endl;
   Solution solution;
   int x;
   while(cin>>x)
   {
       cout<<solution.reverse(x)<<endl;
   }
   return 0;
}

LeetCode - 7. Reverse Integer相关推荐

  1. 【翻转整数考虑溢出】LeetCode 7. Reverse Integer

    LeetCode 7. Reverse Integer Solution1:最笨的方法 class Solution {public:int reverse(int x) {if (!x) retur ...

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

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

  3. LeetCode之Reverse Integer

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

  4. LeetCode - 7 - Reverse Integer

    题目 URL:https://leetcode.com/problems/reverse-integer 解法 这个题目是极其简单的,对于数 x,每次对 10 取余保存为结果,之后 x 除以 10,若 ...

  5. LeetCode 7. Reverse Integer

    问题链接 LeetCode 7 题目解析 给定一个32位有符号整数,求其反转数字. 解题思路 如果是简单反转的话,那这道题就太简单了.题目要求判断溢出问题,32位int类型的范围是-214748364 ...

  6. LeetCode——7. Reverse Integer

    一.题目链接:https://leetcode.com/problems/reverse-integer/ 二.题目大意: 给定一个整数,要求反转该整数之后再返回:如果归返回的整数超过了int型整数的 ...

  7. leetcode No7. Reverse Integer

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

  8. leetcode 7 Reverse Integer

    class Solution { public:int reverse(int x) {int res = 0;while (x != 0) {int t = res * 10 + x % 10;if ...

  9. [LeetCode] Number of 1 Bits Reverse Integer - 整数问题系列

    目录: 1.Number of 1 Bits  - 计算二进制1的个数 [与运算] 2.Contains Duplicate - 是否存在重复数字 [遍历] 3.Reverse Integer - 翻 ...

最新文章

  1. 结队编程-基于gui的四则运算生成器
  2. AspectJ的注解开发AOP:异常抛出通知的学习
  3. C/C++与Matlab混合编程初探
  4. 堆排序python代码实现_python实现堆排序
  5. Halcon学习笔记:xyz_attrib_to_object_model_3d示例
  6. 将机器学习模型部署为服务
  7. pygame游戏开发-简介
  8. 求两个字符串的最长的连续公共子串
  9. 二自由度云台扫描算法_基于二维压电透射式微扫描器的红外超分辨率成像|压电扫描台...
  10. 〖文字素材】 比 较 全 的 血 族 资 料
  11. 【Java】QuickHit游戏
  12. 已解决IndentationError: unindent does not match any oute r indentation Level
  13. 别去赌场了,你永远赢不了“凯利公式”
  14. 电脑仙人掌机器人作文_仙人掌作文3篇
  15. 调试基础知识0(串口调试助手对比 丁丁 大傻 友善)
  16. Scrum板与Kanban如何抉择?敏捷工具:kmgoam板与按照pyluujly
  17. 3D游戏建模师薪水大概是多少?从人生经历来看
  18. 项目选题-口罩识别检测系统
  19. python视觉识别字_机器视觉以及验证码识别
  20. 基于SSM的备忘录管理系统

热门文章

  1. python3 copy_Python3 深浅拷贝
  2. 用java编写圆锥_求java大神帮忙 求大神帮助!Java
  3. html5中地理位置,Chrome中的HTML 5地理位置提示
  4. 信息: 开始协议处理句柄[http-nio-8080]_你必须要知道的HTTP协议原理
  5. python \__call__
  6. Midi 乐器set
  7. 图解TCPIP-以太网(物理层)
  8. freecplus框架-文件操作
  9. 二叉树层次遍历c语言_每日一道 LeetCode (23):二叉树的层次遍历 II
  10. 理想的人才梯队体系特征:40页人才梯队建设实施方案,果断收藏