当前位置:网站首页>leetcode:5259. Calculate the total tax payable [simple simulation + see which range]
leetcode:5259. Calculate the total tax payable [simple simulation + see which range]
2022-06-12 18:43:00 【Review of the white speed Dragon King】

analysis
See where your front falls , Then add up all the previous intervals
The last interval can be added to the current extra part
ac code
class Solution:
def calculateTax(self, brackets: List[List[int]], income: int) -> float:
ans = 0
n = len(brackets)
if income <= brackets[0][0]:
return income * brackets[0][1] / 100
else:
for i in range(n):
if i == 0:
ans += brackets[0][0] * brackets[0][1] / 100
else:
if income >= brackets[i - 1][0] and income <= brackets[i][0]:
ans += (income - brackets[i - 1][0]) * brackets[i][1] / 100
break
else:
ans += (brackets[i][0] - brackets[i - 1][0]) * brackets[i][1] / 100
return ans
summary
Simple simulation But what if the last part of the whole range is exceeded ?
The topic should be made clear
边栏推荐
- Leetcode 416. Split equal sum subset
- 2022.6.12-----leetcode. eight hundred and ninety
- Gospel of audio and video developers, rapid integration of AI dubbing capability
- 国内如何下载Vega
- CEPH deploy offline deployment of CEPH cluster and error reporting FAQ
- Title 66: input 3 numbers a, B, C, and output them in order of size.
- Research Report on the overall scale, major manufacturers, major regions, products and applications of Electric Screwdrivers in the global market in 2022
- Leetcode 494. 目标和
- 国内如何下载ProxyStrike
- 常用问题排查工具和分析神器,值得收藏
猜你喜欢
![Two months later, my second listing anniversary [June 2, 2022]](/img/55/6678659a552ba7dbace330d8b9c3ae.png)
Two months later, my second listing anniversary [June 2, 2022]

【历史上的今天】6 月 12 日:美国进入数字化电视时代;Mozilla 的最初开发者出生;3Com 和美国机器人公司合并

leetcode:6096. 咒语和药水的成功对数【排序 + 二分】

Review of MySQL (4): sorting operation

Title 66: input 3 numbers a, B, C, and output them in order of size.

Review of MySQL (IX): index

论大型政策性银行贷后,如何数字化转型 ?-亿信华辰

The Bean Validation API is on the classpath but no implementation could be found

C语言学习——数据在内存中的存储

liunx部署Seata(Nacos版)
随机推荐
从源码解析 MobX 响应式刷新机制
torch. New usage of where (old but ignored usage)
快速复制浏览器F12中的请求到Postman/或者生成相关语言的对应代码
Mysql ->>符号用法 Json相关
leetcode:6095. 强密码检验器 II【简单模拟 + 不符合直接False】
Leetcode 1049. Weight of the last stone II
Problems that the sap Spartacus e-commerce cloud UI shipping method does not display in the unit test environment
Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of swimming fins in the global market in 2022
Comparison of disk mapping tools for network disk and object cloud storage management
leetcode:5259. 计算应缴税款总额【简单模拟 + 看看在哪个区间】
SCI Writing - Methodology
VirtualLab basic experiment tutorial -5 Poisson bright spot
国内如何下载ProxyStrike
What is SAP support package stack
How to download proxystrike in China
Review of MySQL (VII): use of tables
美团智能配送系统的运筹优化实战-笔记
觀察網站的頁面
no available service ‘null‘ found, please make sure registry config correct
Basic SQL statement - select (single table query)