前言
本文介绍了 LeetCode 第 7 题 , “Reverse Integer”, 也就是 “整数反转” 的问题.
本文使用 C# 语言完成题目,介绍了多种方法供大家参考。
题目
English
LeetCode 7. Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
Input: 123
Output: 321
Example 2:
Input: -123
Output: -321
Example 3:
Input: 120
Output: 21
Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−2^31, 2^(31 − 1) ]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
中文
LeetCode 7. 整数反转
给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。
示例 1:
输入: 123
输出: 321
示例 2:
输入: -123
输出: -321
示例 3:
输入: 120
输出: 2

本文详细解析了LeetCode第7题——整数反转,使用C#语言提供三种解决方案:字符串处理、long类型处理及直接处理int类型数字,同时分析了每种方法的时间和空间复杂度。
最低0.47元/天 解锁文章
958

被折叠的 条评论
为什么被折叠?



