当前位置:网站首页>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
总结
简单模拟 但如果超出了全部区间的最后一部分怎么算呢?
题目应该说清楚一点
边栏推荐
- MYSQL:Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column
- Title 54: take 4 ~ 7 bits of an integer a from the right end.
- USB to serial port - maximum peak serial port baud rate vs maximum continuous communication baud rate
- 用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性
- When openharmony meets openeuler
- 实验10 Bezier曲线生成-实验提高-控制点生成B样条曲线
- dumi 搭建文档型博客
- Gd32f4xx controls dgus variable display
- Why my order by create_ Time ASC becomes order by ASC
- Gd32f4xx controls dgus touch keys
猜你喜欢

How to modify the authorization of sina Weibo for other applications

Gd32f4xx controls dgus touch keys

【矩阵论 & 图论】期末考试复习思维导图

迄今微软不同时期发布的SQL Server各版本之间的大致区别,供参考查阅

PHP:Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocat

Topic 66: input array, exchange the largest element with the first element, exchange the smallest element with the last element, and output array.

Installation and configuration of window version pytorch entry depth learning environment

"Big fat • small lesson" - talk about big file segmentation and breakpoint sequel

间隔两个月,我的第二次上榜纪念日【2022.6.2】

VirtualLab基础实验教程-6.闪耀光栅
随机推荐
2022.6.12-----leetcode.890
Vue —— 进阶 vue-router 路由(二)(replace属性、编程式路由导航、缓存路由组件、路由的专属钩子)
Free measurement of rectangular card [manual drawing ROI] Based on Halcon
309. the best time to buy and sell stocks includes the freezing period
Introduction to service grid and istio - continued
Arrays in JS (including leetcode examples) < continuous update ~>
间隔两个月,我的第二次上榜纪念日【2022.6.2】
【sql语句基础】——查(select)(单表查询)
js二分法
Double non grind one, three side byte, cool. Next time
232-CH579M学习开发-以太网例程-TCP服务器(项目应用封装,局域网或广域网测试)
JS judge palindromes
When openharmony meets openeuler
Review of MySQL (4): sorting operation
A story on the cloud of the Centennial Olympic Games belonging to Alibaba cloud video cloud
Installation and configuration of window version pytorch entry depth learning environment
Eve-ng installation (network device simulator)
C语言学习——数据在内存中的存储
静态内存分配和动态内存分配小结
OpenGL shadow implementation (soft shadow)