leetcode:Reverse Integer

来源:互联网 发布:业绩考核软件 编辑:程序博客网 时间:2024/05/21 17:49


翻转数字

public class Solution {    public int reverse(int x) {        boolean flag = x < 0;        ArrayList<Integer> sta = new ArrayList<>();        x = Math.abs(x);        while(x != 0){            sta.add(x % 10);            x /= 10;        }        for(int i = 0; i < sta.size(); ++i){            x *= 10;            x += sta.get(i);        }        return flag ? -x : x;    }}


0 0