LeetCode初级算法-字符串-2
2019-02-01 12:07
183 查看
题目:整数反转
给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。
示例 1:
输入: 123
输出: 321
示例 2:
输入: -123
输出: -321
示例 3:
输入: 120
输出: 21
C语言解题
int reverse(int x) { int num = 0; int temp; while (x != 0) { temp = num; num = num * 10; num += x % 10; if (num / 10 != temp) return 0; x = x / 10; } return num; }
用num / 10 != temp来判断是否溢出。
相关文章推荐
- LeetCode初级算法-字符串-4
- leetcode初级算法字符串3 字符串中的第一个唯一字符
- LeetCode初级算法-字符串-5
- leetcode初级算法字符串4 有效的字母异位词
- LeetCode探索模块初级算法字符串章节python3代码实现
- [leetcode]初级算法——字符串
- leetcode初级算法 字符串1 反转字符串
- leetcode初级算法字符串2 颠倒整数
- LeetCode初级算法-字符串-3
- LeetCode(初级算法)数组篇--两个数组的交集II c++
- LeetCode-探索-初级-字符串-反转字符串-java
- 【LeetCode-面试算法经典-Java实现】【003-Longest Substring Without Repeating Characters(最长非重复子字符串)】
- 【LeetCode-面试算法经典-Java实现】【205-Isomorphic Strings(同构字符串)】
- leetcode--中级算法--数组和字符串--递增的三元子序列(JavaScript)
- LeetCode-探索-初级-字符串-整数反转-java
- LeetCode初级算法笔记整理
- 【LeetCode-面试算法经典-Java实现】【05-Longest Palindromic Substring(最大回文字符串)】
- [C/C++]_[初级]_[标准库之几种算法库函数的运用,如字符串查找(字符个数查找)、分隔、删除、替换、排序、字符交换位置、大小写转换等等]
- leetcode 初级算法数组8 移动0
- leetcode初级算法数组11 旋转图像