【leetcode】1281. Subtract the Product and Sum of Digits of an Integer
题目如下:
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 = 15Example 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 = 21Constraints:
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的更多相关文章
- [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; ...
- 【leetcode】698. Partition to K Equal Sum Subsets
题目如下: 解题思路:本题是[leetcode]473. Matchsticks to Square的姊妹篇,唯一的区别是[leetcode]473. Matchsticks to Square指定了 ...
- 【LeetCode】479. Largest Palindrome Product 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】124. Binary Tree Maximum Path Sum 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcode ...
- 【LeetCode】698. Partition to K Equal Sum Subsets 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetco ...
- 【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 ...
- 【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 ...
- 【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 ...
- 【leetcode】1043. Partition Array for Maximum Sum
题目如下: Given an integer array A, you partition the array into (contiguous) subarrays of length at mos ...
随机推荐
- 小记--------spark的两种提交模式
spark的两种提交模式:yarn-cluster . yarn-client 图解
- acm java入门(转载)
ACM中java的使用 http://www.cnblogs.com/XBWer/archive/2012/06/24/2560532.html 这里指的java速成,只限于java语法,包括输入输出 ...
- crm--rbac权限组件使用步骤
本人的权限组件码云地址:https://gitee.com/shiguanggege/rbac 里面有文档详细介绍权限组件的使用步骤
- Jmeter之TCP取样器(模拟数据上报压测)
TCP压测 场景:模拟硬件设备上报数据(登录,心跳,GPS定位数据/光感数据/电量数据),对这个功能进行压测 啰嗦一句:TCP压测很简单,只要调通了一个TCP,后续的逻辑判断就用逻辑控制器和正则处理就 ...
- X86逆向8:向程序中插入新区段
本节课我们不去破解程序,本节课学习给应用程序插入一些代码片段,这里我就插入一个弹窗喽,当然你也可以插入一段恶意代码,让使用的人中招, 这里有很多原理性的东西我就不多罗嗦了毕竟是新手入门教程,如果想去了 ...
- Docker入门(一):安装
一. 安装docker 1. 删除已安装的docker yum remove docker \ docker-client \ docker-client-latest \ docker-common ...
- dev gridview表格按钮
固定列的位置 添加按钮控件位置,使用buttonEdit 添加按钮 按钮属性设置 按钮设置后的效果 //注册按钮事件 this.ribtndata.ButtonClick += new DevExpr ...
- 【ES6 】声明变量的方式
var function let const import class
- OSCP-Kioptrix2014-3 后渗透测试
拿到root权限 之前的努力,最终获得了两个session 尝试看看该操作系统的漏洞 kali: searchsploit freebsd 9.0 cp /usr/share/exploitdb/ex ...
- 转载: Linux查看系统开机时间
转自: https://www.cnblogs.com/kerrycode/p/3759395.html 查看Linux系统运行了多久时间,此时需要知道上次开机启动时间: 有时候由于断电或供电故障突然 ...