当前位置:网站首页>力扣每日一题-第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;
}
};边栏推荐
- Meso tetra (4-N, N, n-trimethylaminophenyl) porphyrin (ttmapp) /meso tetra - [4- (BOC threonine) aminophenyl] porphyrin (TAPP thr BOC) supplied by Qiyue
- What is 'EC2-Other' filter in 'Cost Explorer' dashboard mean? [closed]
- Top ten Devops best practices worthy of attention in 2022
- ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers
- MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
- Stack -- 739 Daily temperature
- Fault: administrator account cannot be selected for login
- Is there any difference between a=a+b and a+=b?
- Difference between parametric continuity and geometric continuity
- What is the "danksharding" of V God Kop on Valentine's day?
猜你喜欢
![[C language series] - branch and loop statements](/img/bf/656c9189b4ab4387c5acab1c4a2804.jpg)
[C language series] - branch and loop statements

ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers

Parsing rshub document auto generation API

What are the uses of wireless pressure collectors?

Plugin

Observer mode vs publish subscribe mode

Devops development, operation and maintenance Basics: using Jenkins to automatically build projects and notify by email

ES6 Modularization: export /import

5- (4-benzoimide phenyl) - 10,15,20-triphenylporphyrin (battph2) and its Zn complex (battpzn) / tetra (4-aminophenyl) porphyrin (tapph2) Qiyue supply

VLAN experiment
随机推荐
Programming specification and variables of shell script
Purple red solid meso tetra (o-alkoxyphenyl) porphyrin cobalt (meso-t (2-rop) PCO) / tetra (n, n-diphenyl-p-amino) phenyl porphyrin (tdpatph2)
Installing modules in pycharm
2022-01 Microsoft vulnerability notification
Plugin
What are the uses of static?
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
How to change the password after forgetting the MySQL password (the latest version of 2022 detailed tutorial nanny level)
[chromium] win10 vs2019 environment chromium configuration and compilation.
Common methods for describing 3D models of objects and their advantages and disadvantages
Quickly write MVVM code using source generators
Rearrangement string of leetcode simple question
What are the uses of final?
證券開戶安全麼,有沒有什麼危險呢
51 single chip microcomputer learning notes 7 -- Ultrasonic Ranging
Spark saving to external data source
QT (x): innosetup for software packaging
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
Week 10 - task 3- from point to circle to cylinder
5- (4-benzoimide phenyl) - 10,15,20-triphenylporphyrin (battph2) and its Zn complex (battpzn) / tetra (4-aminophenyl) porphyrin (tapph2) Qiyue supply