魔法师 (@Constanline)Leetcode每日一题 —— 3754. 连接非零数字并乘以其数字和 I 中发帖

思路
直接模拟即可,当然字符串批处理也可以。
代码
class Solution {
public long sumAndMultiply(int n) {
long sum = 0;
int pow10 = 1;
int nVal = 0;
while (n > 0) {
int x = n % 10;
n /= 10;
if (x > 0) {
nVal += pow10 * x;
sum += x;
pow10 *= 10;
}
}
return sum * nVal;
}
}