题目如下:

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. 分词搜索 sphinx3.1.1+php+mysql

    sphinx3.1.1的安装与使用 下载sphinx3.1.1 wget http://sphinxsearch.com/files/sphinx-3.1.1-612d99f-linux-amd64. ...

  2. PHP给图片添加文字水印实例

    PHP给图片添加文字水印实例,支持中文文字水印,是否覆盖原图,自定义设置水印背景色.文字颜色.字体等. 水印类water.class.php var $Path = "./"; / ...

  3. Java 概述和编程基础

    First of all,Java概述: 类是Java程序设计的基石和基本单元: main()方法是程序的入口,它是共有的.静态的,参数String[] args表示一个字符串数组可以传入该程序,用来 ...

  4. Docker ASPNetCore https 四步教你搭建一个网站

    序 本教程需要有自己已经申请好的证书 ,没有证书请参照官方教程. Docker 就不多说了,咱只要知道怎么用先. 环境 core:asp net core 2.2 开发机:win10 LTS 服务器: ...

  5. Stacey矩阵简介

    1. Stacey 矩阵包含哪几个区域? 1区:Simple 第一个区域,需求明确,技术(解决方案)也确定,这类项目就是简单的项目(Simple):比如注册一个新公司,需求很明确,手续也很清楚,就那么 ...

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

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

  7. macbook打印出现乱码解决方案

    系统偏好设置 --> 打印机与扫描仪 --> + (左下角的加号) --> IP --> 输入打印机的ip地址,然后最下面的 “使用选择” 中选中 普通PCL 打印机,(默认的 ...

  8. OO方式实现ALV: cl_salv_table

    这里总结最近用cl_salv_table实现ALV遇到问题和解决办法 FORM set_alv2 . DATA: lv_syrepid TYPE syrepid. lv_syrepid = sy-cp ...

  9. angular实现对百度天气api跨域请求

    申请秘钥:http://lbsyun.baidu.com/apiconsole/key  ,有个百度账号就行ak=开发者秘钥 url地址  :http://api.map.baidu.com/tele ...

  10. C语言实现MD5校验

    根据网上资料,整理验证C程序代码. 接口函数: /****************************************************** *函数名称:Compute_data_m ...