LC.P2544[交替数字和] 方法一:模拟1234567891011class Solution { public int alternateDigitSum(int n) { int ans = 0, sign = 1; for (char c : String.valueOf(n).toCharArray()) { int x = c - '0'; ans += sign * x; sign *= -1; } return ans; }} 时间复杂度:$O(logn)$ 空间复杂度:$O(logn)$