当前位置:网站首页>[LeetCode]7. Integer inversion thirty-nine
[LeetCode]7. Integer inversion thirty-nine
2022-06-13 00:12:00 【PowerDon】
Give a 32 Signed integer of bit , You need to reverse the number on each of the integers .
Example 1:
Input : 123
Output : 321
Example 2:
Input : -123
Output : -321
Example 3:
Input : 120
Output : 21
Be careful :
Suppose our environment can only store 32 Signed integer of bit , The value range is [−231, 231 − 1]. Please follow this assumption , If the integer overflows after inversion, return 0.
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/reverse-integer
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
public class Solution
{
public int Reverse(int x)
{
checked
{
try
{
bool tag = false;
if (x < 0)
{
x = -x;
tag = true;
}
Queue list = new Queue();
int result = 0;
while (x >= 1)
{
list.Enqueue(x % 10);
x /= 10;
}
if (list.Count >= 32)
{
return 0;
}
if (tag)
{
while (list.Count != 0)
{
result -= (int)list.Dequeue() * (int)Math.Pow(10, list.Count);
}
}
else
{
while (list.Count != 0)
{
result += (int)list.Dequeue() * (int)Math.Pow(10, list.Count);
}
}
return result;
}
catch {
return 0; }
}
}
}
边栏推荐
- Masa auth - overall design from the user's perspective
- PMP renewal | PDU specific operation diagram
- How to publish OSM maps locally and customize the mapping
- 2022施工员-设备方向-通用基础(施工员)操作证考试题及模拟考试
- 中科大USTC:Minrui Wang | 基于Transformer的多智能体强化学习的配电网稳压
- 【Matlab】二维曲线
- Binary search the specified number of numbers in the array binary advanced
- Explain bio, NiO, AIO in detail
- OSM地图本地发布-如何生成各省市矢量地图
- OSM map local publishing - how to generate vector maps of provinces and cities
猜你喜欢

安全事故等级划分为哪几级

你真的会用PostGIS中的buffer缓冲吗?

Start of u-boot_ Armboot analysis (I)

Basics of network security (1)

How to control the display and hiding of layergroup through transparency in leaflet

Vscode实现PHP在浏览器实时预览

【HCIE论述】组播IGMP-A

Masa auth - overall design from the user's perspective

H5时代leaflet中还在用DivIcon?
![[matlab] matrix transformation and matrix evaluation](/img/71/b7614e2e4ea2dda0f44f0ea8bcbf45.png)
[matlab] matrix transformation and matrix evaluation
随机推荐
Distributed lock implementation
Memory address mapping of u-boot
华为云会议初体验【华为云至简致远】
Explain bio, NiO, AIO in detail
Binary search the specified number of numbers in the array binary advanced
2022 constructor - Equipment direction - General Foundation (constructor) operation certificate examination questions and simulation examination
[hcie discussion] STP-A
How to quickly query the online status of mobile phones
Pytorch loading model error resolution
2022美容师(技师)上岗证题目及答案
分公司能与员工签劳动合同么
Cherry Blossom powder Dudu
最全预告!华为云精彩议程火速收藏
63. 不同路径 II
3、 Storage system
实战 | UI 自动化测试框架设计与 PageObject 改造
KConfig
【Matlab】矩阵操作
Lower interest rates lead to higher bond prices
A detailed explanation of synchronized