【LeetCode从零单排】No.7 Reverse Integer
前话
题目
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
代码
public class Solution {public int reverse(int x) {int sum = 0;while (Math.abs(x) != 0){if(Math.abs(sum) > Integer.MAX_VALUE / 10){return 0;}sum = sum * 10 + x % 10;x = x / 10;}return sum;}
}
public class Solution {public int reverse(int x) {if(Math.abs(x)>100){return 0;}else{String x_str=Integer.toString(x);char[] x_char = x_str.toCharArray();String x_reverse_str="";//System.out.print(Character.isDigit(x_char[0]));if(Character.isDigit(x_char[0])){ for(int i=(x_str.length()-1);i>=0;i--){x_reverse_str+=x_char[i];} }else{x_reverse_str+=x_char[0];for(int i=(x_str.length()-1);i>=1;i--){x_reverse_str+=x_char[i];} } return Integer.parseInt(x_reverse_str);}}
}
/********************************
* 本文来自博客 “李博Garvin“
* 转载请标明出处:http://blog.csdn.net/buptgshengod
******************************************/
【LeetCode从零单排】No.7 Reverse Integer相关推荐
- 【LeetCode从零单排】No.9 Palindrome Number
题目 这道题是迄今为止最快通过的一道题,改了两次就过了,runtime一般(中等偏下,这点不太满意).Palindrome就是判断一个整数是否对称. Determine whether a ...
- 【LeetCode从零单排】No.8 String to Integer (丧心病狂的一道题)
题目 题目很简单,就是写一个函数把string转换成int,但是通过率只有可怜的11%,难点是要考虑所有情况,特别是int溢出边界,反正我是写了2个小时还没解决,先放到这,有空接着搞,现 ...
- 【LeetCode从零单排】No198.House Robber No91.Decode Ways139 word break(动态规划典型应用)
1.题目 一道典型的Dynamic Programming的题目. You are a professional robber planning to rob houses along a stree ...
- 【LeetCode从零单排】No15 3Sum
题目 Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all ...
- 【LeetCode从零单排】No 3 Longest Substring Without Repeating Characters
题目 Given a string, find the length of the longest substring without repeating characters. For exampl ...
- 【LeetCode从零单排】No 191.Number of 1 Bits(考察位运算)
题目 Write a function that takes an unsigned integer and returns the number of '1' bits it has (also k ...
- 【LeetCode从零单排】No189 .Rotate Array
题目 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the arr ...
- 【LeetCode从零单排】No.169 Majority Element(hashmap用法)
题目 Given an array of size n, find the majority element. The majority element is the element that app ...
- 【LeetCode从零单排】No118 Pascal's Triangle
题目 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, R ...
最新文章
- Python_note5 函数和代码复用+PyInstaller库+数码管绘制
- [linux]在使用rsync时需要注意的小细节
- 用shell写了一个自动编译代码的脚本
- 机器学习——人工神经网络之发展历史(神经元数学模型、感知器算法)
- J2CL –迟到总比不到好
- 理解GL_TRIANGLE_STRIP等绘制三角形序列的三种方式
- Windows环境下多个tomcat启动方法
- 马云:遇见好老板很重要;锤子上海法人变更;摩拜更名美团单车 | 极客头条...
- jq判断是否为整数_jquery怎么判断是否是数字?
- 简述中断处理的6个步骤_基于SCDM软件的CFD前处理工作5个步骤
- ubuntu16 install sogou input
- js排序的时间复杂度_各种排序算法时间复杂度
- 基于hilbert变换的数字信号_基于Hilbert变换处理绝对重力仪测量数据
- 成本要素****没有被分配到成本组件结构01中的成本组件
- c语言反步法编程,CCM模式下Boost电路的反步法非线性控制与仿真.pdf
- Mac Quicktime 录屏带声音
- pd.read_csv处理含中文的文件
- 缓冲流,转换流,序列化流,网络编程
- 电脑没有串口怎么办?
- VMware安装windows server2008R2x64
热门文章
- mysql-5.7.18-winx64 安装 net start mysql 发生系统错误2
- awaitUntil() 方法的使用
- python高通滤波器设计_python实现直方图均衡化,理想高通滤波与高斯低通滤波
- ios开发返回按钮消失_iOS开发之自定义导航栏返回按钮右滑返回手势失效的解决...
- 16进制 hbase phoenix_【建议收藏】HBase表的RowKey设计
- python怎么写csv文件_python怎么写csv文件
- 将长度为n的绳子分为m段求各段乘积的最大值
- android布局翻译,android – 使用翻译动画将视图从一个布局转换为另一个布局
- 检测是否输入字母c语言程序,C语言判断字符是否为可打印字符的方法
- html显示后台传来的byte类型的数据_java的数据类型