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: ...
随机推荐
- SD卡 TF卡 接口引脚定义
- JSP中Out和Request对象详解
内置表示不需要new便可直接使用. 一.基础知识 1.缓冲区:IO最原始是一个一个字节的读取,这就像吃米饭的时候一粒一粒的吃,很没有效率,这时候就有了碗,一碗一碗的吃,岂不痛快. 2.Get提交不能超 ...
- 能使用html/css解决的问题就不要使用JS
为什么说能使用html/css解决的问题就不要使用JS呢?两个字,因为简单.简单就意味着更快的开发速度,更小的维护成本,同时往往具有更好的体验,下面介绍几个实例. 1. 导航高亮 导航高亮是一种很常见 ...
- Android之旅十四 android中的xml文件解析
在我们做有关android项目的时候,肯定会涉及到对xml文件的解析操作.以下给大家介绍一下xml文件的解析.包括DOM.SAX.Pull以及曾经我们用到的DOM4J和JDOM: 要解析的XML文件: ...
- python笔记20-yaml文件写入(ruamel.yaml)
前言 yaml作为配置文件是非常友好的一种格式,前面一篇讲了yaml的一些基础语法和读取方法,本篇继续讲yaml文件写入方法 用yaml模块写入字典嵌套字典这种复杂的数据,会出现大括号{ },不是真正 ...
- ubuntu 设置静态IP GW
网卡配置静态IP地址 编辑文件/etc/network/interfaces: sudo vi /etc/network/interfaces 并用下面的行来替换有关eth0的行:# The prim ...
- Python学习(九)IO 编程 —— 文件读写
Python 文件读写 Python内置了读写文件的函数,用法和C是兼容的.本节介绍内容大致有:文件的打开/关闭.文件对象.文件的读写等. 本章节仅示例介绍 TXT 类型文档的读写,也就是最基础的文件 ...
- SQL VM上磁盘延迟高, 但Host和Storage Array上的延迟却很低的问题
按照下面的步骤, 问题解决. =========================== Per Microsoft DDK, Microsoft storport.sys maintains a dev ...
- JavaScript中的单引号和双引号解决
在使用JavaScript显示消息或者传递字符数据的时候,经常会碰到数据中夹杂单引号(')或者双引号("),这种语句往往会造成JavaScript报错.对此一般采用/'或者/"的解 ...
- Ubuntu 16.04 LTS软件包管理基本操作
前文 Ubuntu 16.04 新特性中我们已经介绍过,随着 Ubuntu 16.04 LTS 的发布,Ubuntu 的软件包管理命令也发生了变化,新系统采用了 Debian 项目中所使用的 APT( ...