[7] 整数反转

This commit is contained in:
Wen 2022-11-08 12:02:37 +08:00
parent db3cd89070
commit 0c57095679
2 changed files with 25 additions and 1 deletions

View File

@ -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;

View File

@ -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