题目如下:

Given an integer number n, return the difference between the product of its digits and the sum of its digits.

Example 1:

Input: n = 234
Output: 15
Explanation:
Product of digits = 2 * 3 * 4 = 24
Sum of digits = 2 + 3 + 4 = 9
Result = 24 - 9 = 15

Example 2:

Input: n = 4421
Output: 21
Explanation:
Product of digits = 4 * 4 * 2 * 1 = 32
Sum of digits = 4 + 4 + 2 + 1 = 11
Result = 32 - 11 = 21

Constraints:

  • 1 <= n <= 10^5

解题思路:送分题。

代码如下:

class Solution(object):
def subtractProductAndSum(self, n):
"""
:type n: int
:rtype: int
"""
total = 0
multi = 1
for i in str(n):
total += int(i)
multi *= int(i)
return multi - total

【leetcode】1281. Subtract the Product and Sum of Digits of an Integer的更多相关文章

  1. [Leetcode] 5279. Subtract the Product and Sum of Digits of an Integer

    class Solution { public int subtractProductAndSum(int n) { int productResult = 1; int sumResult = 0; ...

  2. 【leetcode】698. Partition to K Equal Sum Subsets

    题目如下: 解题思路:本题是[leetcode]473. Matchsticks to Square的姊妹篇,唯一的区别是[leetcode]473. Matchsticks to Square指定了 ...

  3. 【LeetCode】479. Largest Palindrome Product 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  4. 【LeetCode】124. Binary Tree Maximum Path Sum 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcode ...

  5. 【LeetCode】698. Partition to K Equal Sum Subsets 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...

  6. 【LeetCode】124. Binary Tree Maximum Path Sum

    Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start and ...

  7. 【leetcode】1295. Find Numbers with Even Number of Digits

    题目如下: Given an array nums of integers, return how many of them contain an even number of digits. Exa ...

  8. 【leetcode】1074. Number of Submatrices That Sum to Target

    题目如下: Given a matrix, and a target, return the number of non-empty submatrices that sum to target. A ...

  9. 【leetcode】1043. Partition Array for Maximum Sum

    题目如下: Given an integer array A, you partition the array into (contiguous) subarrays of length at mos ...

随机推荐

  1. Educational Codeforces Round 68 (Rated for Div. 2)补题

    A. Remove a Progression 签到题,易知删去的为奇数,剩下的是正偶数数列. #include<iostream> using namespace std; int T; ...

  2. SpringCloud组件及功能介绍

    1.什么是SpringClould?    SpringCloud是一个基于SpringBoot实现的微服务架构开发工具.它为微服务架构中涉及的配置管理.服务治理.断路器.智能路由.微代理.控制总线. ...

  3. Linux操作系统文档

    一 Linux操作系统概述 l为什么要学习Linux操作系统: 1.  大部分服务端都是使用Linux操作系统(Django,爬虫,科学运算等项目是部署到服务器中的) 2.  一些企业和学校(国外学校 ...

  4. golang 客户端

    package main import ( "fmt" "io/ioutil" "net/http" ) func main() { fmt ...

  5. 数值优化(Numerical Optimization)学习系列-目录

    数值优化(Numerical Optimization)学习系列-目录 置顶 2015年12月27日 19:07:11 下一步 阅读数 12291更多 分类专栏: 数值优化   版权声明:本文为博主原 ...

  6. 怎样创建并使用 vue 组件 (component) ?

    组件化开发 需要使用到组件, 围绕组件, Vue 提供了一系列功能方法, 这里仅记录组件的 最简单 的使用方法. 1. 通过 Vue.component(tagName, options) 注册一个 ...

  7. Python 风格指南

    https://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/contents/ 目前个人遵循的基本规范 ...

  8. 二、maven学习

    maven工程运行环境修改 例如maven自带Tomcat6,我们想使用Tomcat7 pom.xml #配置多一个Tomcat7<plugins> <plugin> < ...

  9. 在javascript中:(函数()()是一个匿名函数

    在javascript中:(函数()()是一个匿名函数,它主要使用函数中的变量范围来避免全局变量,影响整个页面环境,并提高代码兼容性. (函数())是标准函数定义,但不会复制到任何变量.所以有一个没有 ...

  10. 【Zabbix】分布式监控系统Zabbix【二】

    一.Zabbix基本操作 1.主机群组.主机.模板.触发器 a.创建主机群组和主机的过程比较简单,不再介绍 b.配置模板: 创建一个模板,将其分组到Template组,添加配置应用: 给应用创建监控项 ...