当前位置:网站首页>LeetCode 1281. Difference of sum of bit product of integer
LeetCode 1281. Difference of sum of bit product of integer
2022-06-24 03:39:00 【freesan44】
Title address (1281. The difference between the sum of the products of integers )
https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/
Title Description
Give you an integer n, Please help calculate and return the integer 「 The product of your numbers 」 And 「 The sum of your numbers 」 Difference . Example 1: Input :n = 234 Output :15 explain : Product of numbers = 2 * 3 * 4 = 24 The sum of your numbers = 2 + 3 + 4 = 9 result = 24 - 9 = 15 Example 2: Input :n = 4421 Output :21 explain : Product of numbers = 4 * 4 * 2 * 1 = 32 The sum of your numbers = 4 + 4 + 2 + 1 = 11 result = 32 - 11 = 21 Tips : 1 <= n <= 10^5
Ideas
Violence law
Code
- Language support :Python3
Python3 Code:
class Solution:
def subtractProductAndSum(self, n: int) -> int:
sList = list(map(int,list(str(n))))
# print(sList)
ji = 1
he = 0
for i in sList:
ji *= i
he += i
return ji-heComplexity analysis
Make n Is array length .
- Time complexity :$O(n)$
- Spatial complexity :$O(1)$
边栏推荐
- Under what circumstances do you need a fortress machine? What are the functions of a fortress machine
- Tke accesses the cluster through kubectl in pod
- Web penetration test - 5. Brute force cracking vulnerability - (3) FTP password cracking
- TRTC audio quality problem
- web渗透测试----5、暴力破解漏洞--(4)Telnet密码破解
- ClickHouse(02)ClickHouse架构设计介绍概述与ClickHouse数据分片设计
- The quick login of QQ cannot be directly invoked through remote login, and the automatic login of QQ can be invoked using VNC
- LeetCode 129. Find the sum of numbers from root node to leaf node
- Event id:7001: after restarting the machine, the World Wide Web failed to start automatically, resulting in inaccessible websites
- Interpreting Tencent cloud product experience through user experience elements
猜你喜欢

Get to know MySQL database

Modstartcms theme introductory development tutorial

On Sunday, I rolled up the uni app "uview excellent UI framework"
Thank you for your recognition! One thank-you note after another

Koom of memory leak

ModStartCMS 主题入门开发教程

在pycharm中pytorch的安装

Modstartcms enterprise content site building system (supporting laravel9) v4.2.0

ModStartCMS 企业内容建站系统(支持 Laravel9)v4.2.0

Do you understand TLS protocol?
随机推荐
What is the difference between server leasing and hosting?
Web penetration test - 5. Brute force cracking vulnerability - (3) FTP password cracking
Koom of memory leak
Do you understand TLS protocol?
Coding Ci of Devops
Modstartcms theme introductory development tutorial
Web penetration test - 5. Brute force cracking vulnerability - (2) SNMP password cracking
What is an edge calculator? How is the unit price of the edge calculator calculated?
内存泄漏之KOOM
Dialogue with Google technical experts: soundstream is expected to be used for general audio coding in the future
Rasa 3.x 学习系列-Rasa 3.2.0 新版本发布
Grpc: how to add API log interceptors / Middleware?
Industrial security experts talk about how to build security protection capability for government big data platform?
Gaussian beam and its matlab simulation
Tke accesses the cluster through kubectl in pod
Chapter 6: UART echo case of PS bare metal and FreeRTOS case development
Tencent cloud ASR product -php realizes the authentication request of the extremely fast version of recording file identification
What does elastic scaling of cloud computing mean? What are the application scenarios for elastic scaling of cloud computing?
web渗透测试----5、暴力破解漏洞--(7)MYSQL密码破解
Paste board based on curl and COS