当前位置:网站首页>leetcode:5259. 计算应缴税款总额【简单模拟 + 看看在哪个区间】
leetcode:5259. 计算应缴税款总额【简单模拟 + 看看在哪个区间】
2022-06-12 18:36:00 【白速龙王的回眸】

分析
看看自己的前落在哪个区间,然后前面的区间全加起来
最后一个区间就加上当前多出来的那部分即可
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
总结
简单模拟 但如果超出了全部区间的最后一部分怎么算呢?
题目应该说清楚一点
边栏推荐
- VirtualLab基础实验教程-5.泊松亮斑
- MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column
- 279. perfect square
- 标准库template学习入门原创
- 每日一博 - 微服务权限一二事
- Problems that the sap Spartacus e-commerce cloud UI shipping method does not display in the unit test environment
- MySQL数据库(28):变量 variables
- Can tonghuashun open an account? Can tonghuashun directly open the security of securities companies on the app
- Topic 66: input array, exchange the largest element with the first element, exchange the smallest element with the last element, and output array.
- Review of MySQL (V): Joint table query and sub query
猜你喜欢

Review of MySQL (VI): usage of Union and limit

快速复制浏览器F12中的请求到Postman/或者生成相关语言的对应代码

C language operation database (SQLite3) call interface function

General differences between SQL server versions released by Microsoft in different periods so far, for reference

Shenzhen has been shut down for 7 days since March 14. Home office experience | community essay solicitation

MySQL - > > symbol usage JSON related

Comparison of disk mapping tools for network disk and object cloud storage management

Review of MySQL (VIII): Transactions

Write a select based concurrent server

To understand Devops, you must read these ten books!
随机推荐
快速复制浏览器F12中的请求到Postman/或者生成相关语言的对应代码
在思科模擬器Cisco Packet Tracer實現自反ACL
间隔两个月,我的第二次上榜纪念日【2022.6.2】
To understand Devops, you must read these ten books!
Write a select based concurrent server
lua记录
In 2021, the global spice and seasoning revenue is about 18720million US dollars, and it is expected to reach 25960million US dollars in 2028
Title 68: there are n integers, so that the previous numbers are moved backward m positions, and the last m numbers become the first m numbers
Gd32f4xx communicates with electric energy meter conforming to dlt645_ two
MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column
JS quick sort
C language practice (4) -- multiplication and division of large numbers
美团智能配送系统的运筹优化实战-笔记
Leetcode topic [string]-541- reverse string II
Introduction to service grid and istio - continued
OpenGL shadow implementation (hard shadow)
This shift, I still have to go
网盘和对象云存储管理之磁盘映射工具比较
Leetcode topic [string] - Sword pointing offer 05- replace spaces
【矩阵论 & 图论】期末考试复习思维导图