2023-08-09力扣每日一题

链接:

1281. 整数的各位积和之差

题意:

十进制每一位的积减去每一位的和

解:

十进制位处理

实际代码:

c++ 复制代码
#include<iostream>
using namespace std;
int subtractProductAndSum(int n)
{
    int t1=1,t2=0;
    while(n)
    {
        t1*=n%10;
        t2+=n%10;
        n/=10;
    }
    //cout<<t1<<" "<<t2<<endl;
    return t1-t2;
}
int main()
{
    int n;cin>>n;
    int ans=subtractProductAndSum(n);
    cout<<ans<<endl;
}

限制:

  • 1 <= n <= 10^5
相关推荐
玖玥拾6 小时前
LeetCode 392 判断子序列
笔记·算法·leetcode
重生之后端学习7 小时前
239. 滑动窗口最大值[困难]✅
java·数据结构·算法·leetcode·职场和发展
INGNIGHT16 小时前
1584.连接所有点的最小费用(最小生成树&并查集union find)
c++·leetcode
wabs66616 小时前
关于二叉树【力扣144.二叉树的前序遍历的思考】
数据结构·c++·算法·leetcode·二叉树
Xin7701 天前
LeetCode 23.合并 K 个升序链表(分治递归)
leetcode
Nil2081 天前
leetcode 105从前序和中序遍历序列构造二叉树
算法·leetcode·职场和发展
Nil2081 天前
leetcode 114二叉树展开为链表
leetcode·链表·深度优先
cz07101 天前
hot100_搜索二维矩阵 II
算法·leetcode
圣保罗的大教堂2 天前
leetcode 3718. 缺失的最小倍数 简单
leetcode
青 春 记 忆2 天前
LeetCode 234. 回文链表|Python 解法详解
python·leetcode·链表