https://oj.leetcode.com/problems/reverse-integer/

一个整数,给反过来,比如123输出321.注意12300的情况,应该输出321,还有-123,是-321.

class Solution {
public:
int reverse(int x) {
if(x == )
return ;
bool isNegative = false;
if(x<)
{
isNegative = true;
x = -x;
}
vector<int> num;
while(x!=)
{
num.push_back( x%);
x = x/;
}
int ans = ;
for(int i = ;i<num.size();i++)
{
ans = ans * ;
ans += num[i]; }
if(isNegative)
ans = ans*(-);
return ans;
}
};

LeetCode OJ-- Reverse Integer的更多相关文章

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

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

  2. LeetCode OJ:Integer to Roman(转换整数到罗马字符)

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  3. leetcode:Reverse Integer 及Palindrome Number

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

  4. LeetCode 7 Reverse Integer & int

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

  5. Leetcode 7. Reverse Integer(水)

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

  6. [LeetCode][Python]Reverse Integer

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

  7. [LeetCode] 7. Reverse Integer 翻转整数

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

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

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

  9. 【LeetCode】Reverse Integer(整数反转)

    这道题是LeetCode里的第7道题. 题目描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321  示例 2: 输入: -123 ...

  10. LeetCode 7. Reverse Integer (倒转数字)

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

随机推荐

  1. [转载] bp神经网络推导

    https://blog.csdn.net/fanxin_i/article/details/80212906 看了这么多就这个推的清楚,转嘞

  2. MySQL多源复制

    MySQL多源复制 1. 配置多源复制 1.1 配置环境如下 1.2 从库的重要参数配置 1.3 在Master上导出需要同步的数据库 1.4 在master上创建复制账号 1.5 备份数据导入 1. ...

  3. APP客户端图片上传PHP接口

    1.客户端 file_get_contents($_FILES['img']['tmp_name']) //获取临时目录下的上传文件流,加密传给接口   2.接口处理端 $img = file_get ...

  4. 命令行下创建MySQL数据库与创建用户以及授权

    先以root用户登录mysql: C:\Users\XXX>mysql -u root -p 输入密码后登录,接下来操作如下: 1.创建数据库 语法:create schema [数据库名称] ...

  5. micrium ucprobe使用笔记

    前段时间在学习ucos-iii的时候,用到了micrium ucprobe,发现在调试的时候,很方便,可以直观的看到任务的运行使用情况,全局变量的值变化等,当然详细的可以参考官方文档,也可以参考网上的 ...

  6. day06 面向对象编程

    面向对象: 面向对象: 世界万物,皆可分类 世界万物,皆为对象   只要是对象,就肯定属于某种品类 只要是对象,就肯定有属性         特性: 多态: 一个统一的接口,多种实现  例如:  一个 ...

  7. luogu3389 【模板】高斯消元法

    #include <algorithm> #include <iostream> #include <cstdio> #include <cmath> ...

  8. C++ STL 的初步认知

    学无止境!!!    尊重他人劳动,尊重出处:http://www.cnblogs.com/shiyangxt/archive/2008/09/11/1289493.html 我已经做了4年的MFC ...

  9. gdb调试手册 一 gdb概述

    一 gdb概述 gdb调试器的目的是让你了解其他的程序在执行的时候发生了什么或者其他程序崩溃时正在做什么 gdb主要能够在运行中做四类事情(包括这些事情中的一些附加的事情)来帮助你获取bugs a 运 ...

  10. Game on Tree

    D - Game on Tree Time limit : 2sec / Memory limit : 256MB Score : 1100 points Problem Statement Ther ...