题目描述:

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

很简单的题目其实用个数组就能解决了,不过用了一下queue,注意负数的情况。

 class Solution {
public:
int reverse(int x) {
bool flg=false;
if(x<){
flg=true;
x=-x;
}
queue<int> a;
while(x>){
a.push(x%);
x/=;
}
x=;
while(!a.empty()){
x=x*;
x+=a.front();
a.pop();
}
return flg?-x:x;
}
};

【leetcode】Reverse Integer的更多相关文章

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

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

  2. 【leetcode】Reverse Integer(middle)☆

    Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 总结:处理整数溢出 ...

  3. 【LeetCode】397. Integer Replacement 解题报告(Python)

    [LeetCode]397. Integer Replacement 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/inte ...

  4. LeetCode 【2】 Reverse Integer --007

    六月箴言 万物之中,希望最美:最美之物,永不凋零.—— 斯蒂芬·金 第二周算法记录 007 -- Reverse Integer (整数反转) 题干英文版: Given a 32-bit signed ...

  5. 【Leetcode】【Easy】Reverse Integer

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

  6. 【LeetCode】Reverse digits of an integer

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

  7. 【leetcode】Reverse Bits(middle)

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  8. 【leetcode】Reverse Words in a String

    今天第一次在leetcode上提交了一个题目,据说这个网站基本上都是名企面试笔试题,今天无意一进去就看到第一题居然就是昨天的腾讯实习生笔试题,赶紧注册了个账号做题. 题目描述: Given an in ...

  9. 【LeetCode7】Reverse Integer★

    题目描述: 解题思路: 反转的方法很简单,重点在于判断溢出的问题,下面给出了两种方法. Java代码: 方法一: 判断溢出方法:在执行完int newResult=result*10+tail语句后, ...

随机推荐

  1. jQuery数组($.each,$.grep,$.map,$.merge,$.inArray,$.unique,$.makeArray)处理函数详解

    1. $.each(array, [callback]) 遍历[常用] 解释: 不同于例遍jQuery对象的$().each()方法,此方法可用于例遍任何对象.回调函数拥有两个参数:第一个为对象的成员 ...

  2. 给一个正在运行的Docker容器动态添加Volume

    给一个正在运行的Docker容器动态添加Volume本文转自:http://dockone.io/article/149 [编者的话]之前有人问我Docker容器启动之后还能否再挂载卷,考虑到mnt命 ...

  3. (转)Xcode调试技巧

    转自http://www.apkbus.com/android-140340-1-1.html 这篇文章给大家带来的是一些Xcode实用技巧,比如: • 摆脱NSlog打印输出,使用断点日志. • 摆 ...

  4. mysql备份与还原

    一.直接拷贝数据库文件 直接拷贝数据库文件一般是使用文件系统备份工具cp,适合小型数据库,是最可靠的. 当你拷贝数据库文件时,必须保证表没有正在使用.如果服务器在你拷贝一个表的时候改变这个表,拷贝就失 ...

  5. angular.js初探

    2015年7月27日 22:26:35 星期一 用在我论坛里的小栗子: 先列出来一级回帖, 点击帖子前边的"查看回复"按钮无刷新的去请求该帖子的所有回复 首先要引用js文件, 我这 ...

  6. properties配置文件的读取和写入

    /** * 类名:PropertiesUtil * 功能:提供对properties配置文件的读取和写入 * @author ChengTao */package com.xy.xyd.rest.bi ...

  7. Java中hashCode()方法以及HashMap()中hash()方法

    Java的Object类中有一个hashCode()方法: public final native Class<?> getClass(); public native int hashC ...

  8. Django~Views

    In Django, web pages and other content are delivered by views. To get from a URL to a view, Django u ...

  9. 手把手教你实现折线图之------安卓最好用的图表库hellocharts之最详细的使用介绍

    因为项目需要搞一个折线图,按照日期显示相应的成绩,所以有了本文. 以前用过一次XCL-chart,但是感觉只适合固定图表,不去滑动的那种,因为你一滑动太卡了你懂得(毕竟作者好久没更新优化了),拙言大神 ...

  10. 【python】time,datetime,string相互转换

    来源:http://essen.iteye.com/blog/1452098 #把datetime转成字符串 def datetime_toString(dt): return dt.strftime ...