【leetcode】Reverse Integer
题目描述:
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的更多相关文章
- 【LeetCode】Reverse Integer(整数反转)
这道题是LeetCode里的第7道题. 题目描述: 给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转. 示例 1: 输入: 123 输出: 321 示例 2: 输入: -123 ...
- 【leetcode】Reverse Integer(middle)☆
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 总结:处理整数溢出 ...
- 【LeetCode】397. Integer Replacement 解题报告(Python)
[LeetCode]397. Integer Replacement 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/inte ...
- LeetCode 【2】 Reverse Integer --007
六月箴言 万物之中,希望最美:最美之物,永不凋零.—— 斯蒂芬·金 第二周算法记录 007 -- Reverse Integer (整数反转) 题干英文版: Given a 32-bit signed ...
- 【Leetcode】【Easy】Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Have you ...
- 【LeetCode】Reverse digits of an integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Have you ...
- 【leetcode】Reverse Bits(middle)
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【leetcode】Reverse Words in a String
今天第一次在leetcode上提交了一个题目,据说这个网站基本上都是名企面试笔试题,今天无意一进去就看到第一题居然就是昨天的腾讯实习生笔试题,赶紧注册了个账号做题. 题目描述: Given an in ...
- 【LeetCode7】Reverse Integer★
题目描述: 解题思路: 反转的方法很简单,重点在于判断溢出的问题,下面给出了两种方法. Java代码: 方法一: 判断溢出方法:在执行完int newResult=result*10+tail语句后, ...
随机推荐
- MySQL用法
查询数据库表 通过查询INFORMATION_SCHEMA.TABLES查询数据库表的结构信息 SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TAB ...
- speex介绍
1介绍 Speex是一套主要针对语音的开源免费,无专利保护的音频压缩格式.Speex工程着力于通过提供一个可以替代高性能语音编解码来降低语音应用输入门槛 .另外,相对于其它编解码器,Speex也很适合 ...
- Linux Vsftpd 连接超时解决方法
Linux Vsftpd 连接超时解决方法 2013-11-13 10:58:34| 分类: 默认分类|举报|字号 订阅 解决方法(http://www.lingdus.com/thread ...
- android studio从1.5更新到2.0后terminal无法运行gradle命令,提示无法找到gradle命令
android studio从1.5更新到2.0后terminal无法运行gradle命令,提示无法找到gradle命令. 'gradle' 不是内部或外部命令,也不是可运行的程序 或批处理文件. 设 ...
- Java中使用Collections.sort()方法对数字和字符串泛型的LIst进行排序
在List的排序中常用的是Collections.sort()方法,可以对String类型和Integer类型泛型的List集合进行排序. 首先演示sort()方法对Integer类型泛型的List排 ...
- Unity3d NavMesh获得地面高度
UnityPro内置的NavMesh有几个API很有用 NavMesh.SamplePosition 根据给的点进行采样,可传入最大距离,返回true说明采样到了点,否则采样失败(可以用来获得地形高度 ...
- Java for LeetCode 218 The Skyline Problem【HARD】
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- SQL中关于字符串的处理
DECLARE @STR VARCHAR(MAX),@PRAM VARCHAR(20)SET @STR='中华人民共和国万岁'--字符串连接SET @STR=@STR+'an'+@STR --字符串拆 ...
- 零件分组_DP
问题 C: 零件分组 时间限制: 1 Sec 内存限制: 64 MB提交: 31 解决: 14[提交][状态][讨论版] 题目描述 某工厂生产一批棍状零件,每个零件都有一定的长度(Li)和重量(W ...
- 【leetcode】Edit Distance (hard)
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...