Skip to content

Latest commit

 

History

History
82 lines (58 loc) · 1.22 KB

[1281] 整数的各位积和之差.md

File metadata and controls

82 lines (58 loc) · 1.22 KB
title tags categories author comments updated permalink mathjax top description date
[1281] 整数的各位积和之差
leetcode
leetcode
张学志
true
false
false
false
...
2019-12-31 16:21:21 -0800

题目描述

给你一个整数 n,请你帮忙计算并返回该整数「各位数字之积」与「各位数字之和」的差。

 

示例 1:

输入:n = 234
输出:15 
解释:
各位数之积 = 2 * 3 * 4 = 24 
各位数之和 = 2 + 3 + 4 = 9 
结果 = 24 - 9 = 15

示例 2:

输入:n = 4421
输出:21
解释: 
各位数之积 = 4 * 4 * 2 * 1 = 32 
各位数之和 = 4 + 4 + 2 + 1 = 11 
结果 = 32 - 11 = 21

 

提示:

  • 1 <= n <= 10^5
Related Topics
  • 数学
  • 题目代码

    class Solution {
    public:
        int subtractProductAndSum(int n) {
    
        }
    };

    题目解析

    方法一

    方法二

    方法三