当前位置:网站首页>力扣每日一题-第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;
}
};边栏推荐
- Rich material libraries make modeling easy and efficient for developers
- Week 10 - task 3- from point to circle to cylinder
- QT (x): innosetup for software packaging
- Quickly write MVVM code using source generators
- Where is the Gcov symbol- Where are the gcov symbols?
- Difference between URI and URL
- Difference between static and final
- Week 10 - task 1- fill in the blank: line class inherits point class
- How does MySQL implement distributed locks?
- The most complete machine learning model training process
猜你喜欢

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

Why can't the article be posted?

Sourcetree remote red exclamation point
![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
![[high concurrency] deeply analyze the callable interface](/img/fb/89ebd5592f1383c8015a47cec78a59.jpg)
[high concurrency] deeply analyze the callable interface

Rich material libraries make modeling easy and efficient for developers

Manual (functional) test 1

Purple red solid meso tetra (o-alkoxyphenyl) porphyrin cobalt (meso-t (2-rop) PCO) / tetra (n, n-diphenyl-p-amino) phenyl porphyrin (tdpatph2)

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

Parsing rshub document auto generation API
随机推荐
[deep learning] - maze task learning I (to realize the random movement of agents)
Internet enterprises need CRM software to help
Sourcetree remote red exclamation point
Difference between parametric continuity and geometric continuity
Creation of Arduino uno development environment
Skills of writing test cases efficiently
Awk of shell script
MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
Difference between URI and URL
Why Houdini made the pyside2 plug-in crash
Can I cast int to a variable of type byte? What happens if the value is larger than the range of byte type?
It turns out that the joys and sorrows of programmers are not interlinked
Fault: NetBt log for id4321
Conditional test, if and case conditional test statements of shell script
Leetcode theme [array] -217- there are duplicate elements
Clickhouse data type
What is the "danksharding" of V God Kop on Valentine's day?
2022.02.15 - SX10-31. House raiding III
QT writing map comprehensive application 58 compatible with multi browser kernel
Haar cascades and LBP cascades in face detection [closed] - Haar cascades vs. LBP cascades in face detection [closed]