[Leetcode]Reverse Integer
核心思想:原数对10取余数赋值给新数后降一位,再把新数升一位加上下一次原数取余值,直到原数降为0。
解法如下:
int reverse(int x) {
bool minus = false;
if(x<)
{
x= -x;
minus = true;
}
int a=;
while(x)
{
a*=;
a+=x%;
x/=;
}
return minus?-a:a;
[Leetcode]Reverse Integer的更多相关文章
- LeetCode: Reverse Integer 解题报告
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- [LeetCode] Reverse Integer 翻转整数
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to ...
- C++ leetcode::Reverse Integer
第一天上课,数据库老师说对于计算机系的学生,凡是在课本上学到的专业知识都是过时的.深以为然,感觉大学两年半真的不知道学了什么,为未来感到担忧,C++也不敢说是精通,入门还差不多.最近丧的不行,不管怎么 ...
- [Leetcode] reverse integer 反转整数
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...
- LeetCode——Reverse Integer(逆置一个整数)
问题: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321 Ha ...
- Leetcode: Reverse Integer 正确的思路下-要考虑代码简化
题目: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 Have ...
- leetcode:Reverse Integer【Python版】
1.在进入while之前,保证x是非负的: 2.符号还是专门用flag保存 =================== 3.另一思路:将integer转换成string,然后首位swap,直至中间: cl ...
- LeetCode——Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 Have you ...
- leetcode reverse integer&&Palindrome Number
public class Solution { public int reverse(int x) { int ret=0; while(x!=0) { int t=x%10; ret=ret*10+ ...
随机推荐
- 【UVA11082】Matrix Decompressing(有上下界的网络流)
题意:给出一个矩阵前i列所有元素的和,和前j行所有元素的和,求这个矩阵解压以后的原型.(答案不唯一) n,m<=20,1<=a[i,j]<=20 思路:这道题把边上的流量作为原先矩阵 ...
- Redis 缓存 + Spring 的集成示例
参考网址:http://blog.csdn.net/defonds/article/details/48716161
- 去空格 whitespaceAndNewlineCharacterSet和过滤字符串
一.过滤字符串 可以使用stringByTrimmingCharactersInSet函数过滤字符串中的特殊符号 首先自己定义一个NSCharacterSet, 包含需要去除的特殊符号 NSChara ...
- Ubuntu 试用Android L版本
Android L是最近google一个大更新的版本,目前google开发了android L的开发者预览版本,对于一个android 开发者来说很定是要下载下来体验一把,顺便也要了解一下Androi ...
- 异步I/O操作
今天在看boost库的时候注意到异步I/O操作时,缓冲区有效性问题. 如何实现异步操作:以异步读操作为例async_read(buffer, handler): void handler() {} v ...
- EAA脚本语言0.2
对上一版的改进.IL生成问题大部分解决了. 运行效果 脚本源码 #using "System"; #using "System.Drawing"; #using ...
- linux和mac下的nginx和php的安装
linux版本相关文档:http://www.nginx.cn/231.html 一.安装php 1.下载包,这里以php 5.3.10为例 2.执行下面shell命令 注意:下面配置的命令中第一行 ...
- verilog循环结构
1. always(posedge CLOCK) . case(i) . . : . ) ’d0; i <= i + ’b1; end . ’b1; C1 <= C1 + ’b1; end ...
- vs2015里给c#添加轮廓折叠功能
轮廓折叠,在看代码时非常有用的功能,可以暂时屏蔽大段不相关的if/else分支 记得以前老版vs里是自带这功能的,c++和c#都有 但不知为啥最新的2015里c#没有了,搜了下原来是要装插件: htt ...
- Html命名锚
这个有什么用 案例 参考资料 这个有什么用 嘛, 不管写博客,还是公司的wiki,一般开头都会有个目录什么的, 这时候命名描就有用了, 所谓的描就是书签. 案例 比如这篇博客的目录,首先建立一个无序列 ...