魔法师 (@Constanline)Leetcode每日一题 —— 3783. 整数的镜像距离 中发帖

思路 
今天的题跟昨天是不是顺序反了,把昨天反转数字的功能拿来就好了。 
代码 
class Solution {
    public int mirrorDistance(int n) {
        int num = n;
        // 反正数字
        int rv = 0;
        while (num > 0) {
            rv = rv * 10 + num % 10;
            num /= 10;
        }
        return Math.abs(rv - n);
    }
}
 
 
Back to Top