leetcode 整数反转(简单粗暴java)

纯函数(虽然很没技术含量)

class Solution {
    public int reverse(int x) {
        try {
            if (x < 0) {
                return -Integer.parseInt(new StringBuffer("" + Math.abs(x)).reverse().toString());
            }
            return Integer.parseInt(new StringBuffer("" + Math.abs(x)).reverse().toString());
        } catch (NumberFormatException e) {
            return 0;
        }
        
    }
}

你可能感兴趣的:(leetcode 整数反转(简单粗暴java))