[7] 整数反转
This commit is contained in:
parent
db3cd89070
commit
0c57095679
|
|
@ -5,7 +5,7 @@ package leecode;/*
|
|||
*/
|
||||
|
||||
// @lc code=start
|
||||
class Solution {
|
||||
class No6 {
|
||||
public String convert(String s, int numRows) {
|
||||
if (numRows == 0 || numRows == 1) return s;
|
||||
int structNum = numRows + numRows - 2;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package leecode;
|
||||
|
||||
/*
|
||||
* @lc app=leetcode.cn id=7 lang=java
|
||||
*
|
||||
* [7] 整数反转
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
class No7 {
|
||||
public int reverse(int x) {
|
||||
int res = 0, y = Math.abs(x);
|
||||
while (y != 0) {
|
||||
if (res < Integer.MIN_VALUE / 10 || res > Integer.MAX_VALUE / 10) {
|
||||
return 0;
|
||||
}
|
||||
res = res * 10 + y % 10;
|
||||
y /= 10;
|
||||
}
|
||||
return x >= 0 ? res : - res;
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Loading…
Reference in New Issue