Reverse digits of an integer.

Example1: x = , return
Example2: x = -, return -
class Solution {
public:
int reverse(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(x == ) return x;
int flag = ; if(x < )
{
x*= -;
flag = -;
}
vector<int> result;
while(x)
{
int temp = x %;
result.push_back(temp);
x/=;
}
int num = ;
for(int i = ; i< result.size(); i++)
{
num +=result[i];
num*=;
} return flag*num/ ;
}
};

LeetCode_Reverse Integer的更多相关文章

  1. LeetCode 7. Reverse Integer

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

  2. Integer.parseInt 引发的血案

    Integer.parseInt 处理一个空字符串, 结果出错了, 程序没有注意到,搞了很久, 引发了血案啊!! 最后,终于 观察到了, 最后的部分: Caused by: java.lang.NoC ...

  3. 由一个多线程共享Integer类变量问题引起的。。。

    最近看到一个多线程面试题,有三个线程分别打印A.B.C,请用多线程编程实现,在屏幕上循环打印10次ABCABC- 看到这个题目,首先想到的是解决方法是定义一个Integer类对象,初始化为0,由3个线 ...

  4. [LeetCode] Integer Replacement 整数替换

    Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...

  5. [LeetCode] Integer Break 整数拆分

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  6. [LeetCode] Integer to English Words 整数转为英文单词

    Convert a non-negative integer to its english words representation. Given input is guaranteed to be ...

  7. [LeetCode] Roman to Integer 罗马数字转化成整数

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

  8. [LeetCode] Integer to Roman 整数转化成罗马数字

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

  9. [LeetCode] String to Integer (atoi) 字符串转为整数

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

随机推荐

  1. altium designer Summer09出现的问题解决方案

    在编译原理图时,引脚和连线旁边出现很多红线,提示 error:signal with no driver. 原理图没有加入到Project里. 第一次导入没问题,但是改了个元件的封装,在更新一下(De ...

  2. 响应头location 页面跳转

    登陆:http://192.168.32.161/DEVOPS/index.php/Index/do_login Cache-Control no-store, no-cache, must-reva ...

  3. android开发论坛

    http://www.hiapk.com/ http://bbs.hiapk.com/ http://bbs.gfan.com/ http://bbs.anzhi.com/ http://www.ap ...

  4. NOI2013 树的计数

    题目:http://uoj.ac/problem/122 85%做法: 动态规划. 首先重编号,BFS序变成1...n,然后DFS序相应重编号. 记pos[i]为i号点在DFS中的位置,即pos[d[ ...

  5. 湖南生第八届大学生程序设计大赛原题 C-Updating a Dictionary(UVA12504 - Updating a Dictionary)

    UVA12504 - Updating a Dictionary 给出两个字符串,以相同的格式表示原字典和更新后的字典.要求找出新字典和旧字典的不同,以规定的格式输出. 算法操作: (1)处理旧字典, ...

  6. java算法之身份证号码验证

    调用时直接 new IDCard().verify(身份证id);就可以了 实现代码如下: public class IDCard { private String _codeError; //wi ...

  7. AndroidStudio常见提示

    Required:请求的是String字符串 .     Found:   et.getText()返回的是text.Editable

  8. Lucene 高亮功能

    原文转载自: http://qindongliang1922.iteye.com/blog/1953409 高亮功能一直都是全文检索的一项非常优秀的模块,在一个标准的搜索引擎中,高亮的返回命中结果,几 ...

  9. c#、sql数据库备份还原

    1.在项目中添加SQLDmo dll文件引用(SQLDMO(SQL Distributed Management Objects,SQL分布式管理对象)) 2在相应页面加using SQLDMO引用 ...

  10. java NumberForMate的使用

    有时候我们需要将数字转化为字符串,并且转化后的长度要一定.比如00012这种类型.这时候我们就可以使用NumberForMate这个方法: NumberFormat numberFormat = Nu ...