1 - Reverse Integer
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Discuss: 1.If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
2.Reversed integer overflow.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReverseInteger
{
class Program
{
/*Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Discuss: 1.If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.
2.Reversed integer overflow.*/
static void Main(string[] args)
{
//"-2147483648","2147483647",
int x = ;
int y = Reverse(x);
} public static int Reverse(int x)
{
int result = ;
while (x != )
{
//if(y*10/10!=y) return 0;
if (result > int.MaxValue / )
return ;
if (result < int.MinValue / )
return ;
result = result * + x % ;
x /= ;
} return result;
}
}
}
1 - Reverse Integer的更多相关文章
- Python字符串倒序-7. Reverse Integer
今天做了下LeetCode上面字符串倒序的题目,突然想Python中字符串倒序都有哪些方法,于是网上查了下,居然有这么多种方法: 个人觉得,第二种方法是最容易想到的,因为List中的reverse方法 ...
- [LintCode] Reverse Integer 翻转整数
Reverse digits of an integer. Returns 0 when the reversed integer overflows (signed 32-bit integer). ...
- 65. Reverse Integer && Palindrome Number
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, re ...
- LeetCode 7 Reverse Integer(反转数字)
题目来源:https://leetcode.com/problems/reverse-integer/ Reverse digits of an integer. Example1: x = 123, ...
- No.007 Reverse Integer
7. Reverse Integer Total Accepted: 153147 Total Submissions: 644103 Difficulty: Easy Reverse digits ...
- leetcode第七题Reverse Integer (java)
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, retu ...
- Reverse Integer 2015年6月23日
题目: Reverse digits of an integer. Example1: x = , return Example2: x = -, return - 思路:递归 解答: / test ...
- Reverse Integer - 反转一个int,溢出时返回0
Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, retur ...
- LeetCode之Easy篇 ——(7)Reverse Integer
7.Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: Out ...
- LeetCode之“数学”:Reverse Integer && Reverse Bits
1. Reverse Integer 题目链接 题目要求: Reverse digits of an integer. Example1: x = 123, return 321 Example2: ...
随机推荐
- AskUsingForm_c函数
IDA SDK里面提供的UI(user interface)函数 AskUsingForm_c,该函数弹出一个对话框,而对话框的外观形式,就由此函数的第一个参数form(const char *类型) ...
- 模板方法在Spring事务中的应用
事务对于我们来讲不并陌生,也是在实际应用中一直都在使用.在JDBC中,事务大致的使用结构如下: 开启事务 业务逻辑处理 提交事务 Spring只是对事务进行了扩展和封装使用,现在看看在内部它是如何工作 ...
- PHP str_pad() 函数
str_pad() 函数把字符串填充为指定的长度. 进入 详细介绍页面
- Unable to load DLL 'opencv_core290'
问题: In my winforms application I need to use some Emgu.CV libraries (I have installed Emgu 2.9). Pro ...
- svn使用经验---不断总结
删除文件或文件夹 svn rm 名字 --force svn ci (系统会提示输入提交日志) 执行完这两步后,才能被真正删除 添加文件或文件夹 svn add 文件名 --force ...
- 淘宝API开发第一步
1.登录淘宝开放平台:http://open.taobao.com/ 2.添加网站 (验证完网站后,会提醒“JSSDK以激活提交审核按钮”,这个需要的UV达100,按钮才会亮,审核过程中也得保持UV的 ...
- lua中遍历table的几种方式比较
当我在工作中使用lua进行开发时,发现在lua中有4种方式遍历一个table,当然,从本质上来说其实都一样,只是形式不同,这四种方式分别是: for key, value in pairs(tbtes ...
- PHP闭包--匿名函数
匿名函数(Anonymous functions),也叫闭包函数(closures),允许 临时创建一个没有指定名称的函数.最经常用作回调函数(callback)参数的值.当然,也有其它应用的情况. ...
- s:iterator循环输出数字
1.在action里加上maxNum属性,GET SET方法2.第一种写法(推荐) <s:iterator value="new int[maxNum]" status=&q ...
- android 设置屏幕方向
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//通过程序改变屏幕显示的方向 1.landscape:横屏(风景 ...