vlambda博客
学习文章列表

21天LeetCode打卡,第18天,整数的各位积和之差

暴力:

class Solution{public: int subtractProductAndSum(intn) { int n_sum =0; int n_product = 1; int rem =0; while (n != 0) { rem = n % 10; n_sum += rem; n_product *= rem; n /= 10; } return n_product - n_sum; }};