본문 바로가기
python-algorithm

leetcode 2303. Calculate Amount Paid in Taxes

by 무적김두칠 2022. 7. 7.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution:
    def calculateTax(self, brackets: List[List[int]], income: int-> float:
        upper= min(brackets[0][0],income)
        rate=brackets[0][1]
        answer = upper * rate / 100
        income-=upper
        for i in range(1,len(brackets)):
            if income<=0: break
            else:
                upper = min(brackets[i][0]-brackets[i-1][0], income)
                rate = brackets[i][1]
                income -= upper
            answer += upper * rate / 100
        return(answer)
cs
반응형

댓글