当前位置:网站首页>力扣每日一题-第30天-1281.整数的各位积和之差
力扣每日一题-第30天-1281.整数的各位积和之差
2022-06-29 06:32:00 【重邮研究森】
2022.6.28今天你刷题了吗?
题目:
给你一个整数 n,请你帮忙计算并返回该整数「各位数字之积」与「各位数字之和」的差。
分析:
给定一个整数,完成各个位的积之乘,和各位的和,然后用积-和。例如
123
积:1*2*3=6
和:1+2+3=6
结果=积-和=6-6=0
解析:
class Solution {
public:
int subtractProductAndSum(int n) {
int mul = 1;
int sum = 0;
while (n != 0)
{
mul *= n % 10;
sum += n % 10;
n /= 10;
}
return mul - sum;
}
};边栏推荐
- ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
- Love that can't be met -- what is the intimate relationship maintained by video chat
- Will the order of where conditions in MySQL affect the union index? Will where 1 =1 affect the use of the index? Does where 1 =1 affect the use of indexes?
- Hyperledger Fabric 2. X custom smart contract
- 想请教一下,究竟有哪些劵商推荐?在线开户是安全么?
- Functions and arrays of shell scripts
- 2022.02.15 - 240. Lucky number in matrix
- Week 10 - task 1- fill in the blank: line class inherits point class
- Est - ce que l'ouverture d'un compte de titres est sécurisée? Y a - t - il un danger?
- The most complete machine learning model training process
猜你喜欢

Easy to understand TCP four waves (multi picture explanation)
![ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience](/img/fd/4c24e10fc91a7ce7e709a0874ba675.jpg)
ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience

Creation of Arduino uno development environment

The simple problem of leetcode is to divide an array into three parts equal to sum

Internet enterprises need CRM software to help

It turns out that the joys and sorrows of programmers are not interlinked

Longest substring between two identical characters of leetcode simple question

Maximum ascending subarray sum of leetcode simple problem

Quickly write MVVM code using source generators

Love that can't be met -- what is the intimate relationship maintained by video chat
随机推荐
5,10-di (4-aminophenyl) - 15,20-diphenylporphyrin (cis-dadph2) /5,15-di (4-aminophenyl) - 10,20-diphenylporphyrin (trans-dadph2) / (tri-apph2) supplied by Qiyue
What are the uses of static?
Awk of shell script
2-nitro-5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin (no2tdmpp) H2) /5,10,15,20-tetra (4-methylphenyl) porphyrin (TMPP) H2) Qiyue porphyrin products
2022.02.15 - 240. Lucky number in matrix
The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers
Sum of digits under k-ary representation of leetcode simple problem
Hyperledger Fabric 2. X custom smart contract
Benign competition will promote each other
51 lines of code, self-made TX to MySQL software!
Jenkins operation Chapter 5 trigger, configuration webhook, Jenkins parameterized construction
Manual (functional) test 1
Clickhouse data type
2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin copper (no2tmpp) Cu) /2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin (no2tmpp) H2) Qiyue porphyrin supply
QT (x): control operation
[deep learning] - maze task learning I (to realize the random movement of agents)
Mongodb paging method
Loosely matched jest A value in tohavebeencalledwith - loose match one value in jest toHaveBeenCalledWith
Stack -- 739 Daily temperature
ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience