模拟
Problem: 100942. 整数的镜像距离
[TOC]
思路
按题意模拟计算。
Code
执行用时分布0ms击败100.00%;消耗内存分布8.36MB击败52.83%
###C
int mirrorDistance(int n) {
int n1 = 0;
for (int x = n; x; x /= 10)
n1 = n1 * 10 + x % 10;
return abs(n - n1);
}
###Python3
class Solution:
def mirrorDistance(self, n: int) -> int:
return abs(n - int(str(n)[::-1]))