LeetCode题解——Reverse Integer
题目:
数字翻转,即输入123,返回321;输入-123,返回-321。
代码:
class Solution {
public:
int reverse(int x) {
int result = , sign = ;
if(x < ) //负数转换为正数统一处理
{
x = -x;
sign = -;
}
while(x != )
{
result *= ;
result += x % ;
x /= ;
}
return result * sign; //返回时记得加上符号
}
};
LeetCode题解——Reverse Integer的更多相关文章
- leetcode题解||Reverse Integer 问题
problem: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 ...
- LeetCode 7 Reverse Integer(反转数字)
题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...
- [LeetCode 题解]: Reverse Nodes in K-Groups
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a li ...
- leetcode:Reverse Integer 及Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- LeetCode 7 Reverse Integer & int
Reverse Integer 想用余10直接算,没想到 -123%10 是 7, 原因 -123-(-123//10*10) r=a-n*[a/n] 以上,r是余数,a是被除数,n是除数. 唯一不同 ...
- Leetcode 7. Reverse Integer(水)
7. Reverse Integer Easy Given a 32-bit signed integer, reverse digits of an integer. Example 1: Inpu ...
- leetcode:Reverse Integer(一个整数反序输出)
Question:Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 ...
- [LeetCode][Python]Reverse Integer
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/reverse ...
- LeetCode 7. Reverse Integer(c语言版)
题目: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123Output: 321 Ex ...
随机推荐
- Competing in a data science contest without reading the data
Competing in a data science contest without reading the data Machine learning competitions have beco ...
- DJANGO的ORM的Q查询作多字段外键的模糊查询样码
工作中用到的,存照一下. from django.db.models import Q if self.kwargs.has_key('search_pk'): search_pk = self.kw ...
- Linux---More命令 初级实现
Linux: more已实现:more filename , quit不需要回车未实现:command | more 重定向 ,显示百分比 Waiting... /* Linux: more 已实现: ...
- HDU4607+BFS
/* bfs+求树的直径 关键:if k<=maxs+1 直接输出k-1: else: k肯定的是包括最长路.先从最长路的起点出发,再走分支,最后到达最长路的终点. 因此是2*(k-(maxs+ ...
- php关于private、public成员变量访问问题
如果类里面定义了__get($name)方法,则不论类的private成员还是public成员,都能够在类的外面通过类似$class->name访问到.如果是public变量,则不会自动调用ge ...
- spring aop环绕通知
[Spring实战]—— 9 AOP环绕通知 假如有这么一个场景,需要统计某个方法执行的时间,如何做呢? 典型的会想到在方法执行前记录时间,方法执行后再次记录,得出运行的时间. 如果采用Sprin ...
- WCF之各种WCF引用方式
写在开头:本文内容来自 WCF全面解析中的一个经典例子,如果你已经看过了,那么可以忽略本文,本文旨在和大家分享不一样的WCF使用方法. 准备工作: 1.创建解决方案WCFService(当然名字可以任 ...
- Android开发之Bitmap.Config.RGB_565
在学习xutils框架的时候,看到sample代码中有一行这样的代码: bitmapUtils.configDefaultBitmapConfig(Bitmap.Config.RGB_565); Bi ...
- JPA详解
2006 年 5 月 2 日,EJB 3.0 规范最终版由 JCP(Java Community Process) 正式公布,标准号为 JSR(Java Specification Request)2 ...
- Codeforces Round #228 (Div. 2) C. Fox and Box Accumulation(贪心)
题目:http://codeforces.com/contest/389/problem/C 题意:给n个箱子,给n个箱子所能承受的重量,每个箱子的重量为1: 很简单的贪心,比赛的时候没想出来.... ...