File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
calculate-amount-paid-in-taxes Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/calculate-amount-paid-in-taxes
49
+
48
50
https://leetcode.cn/problems/third-maximum-number/
49
51
50
52
https://leetcode.cn/problems/toeplitz-matrix/
Original file line number Diff line number Diff line change
1
+ function calculateTax ( brackets : number [ ] [ ] , income : number ) : number {
2
+ let a = 0 ;
3
+ for ( let i = 0 ; i < brackets . length ; i ++ ) {
4
+ if ( income === 0 ) return a ;
5
+ else if ( income >= brackets [ i ] [ 0 ] ) {
6
+ if ( i === 0 ) {
7
+ if ( brackets [ i ] [ 1 ] === 0 ) a += 0 ;
8
+ else a += brackets [ i ] [ 0 ] * ( brackets [ i ] [ 1 ] / 100 ) ;
9
+ } else {
10
+ a += ( brackets [ i ] [ 0 ] - brackets [ i - 1 ] [ 0 ] ) *
11
+ ( brackets [ i ] [ 1 ] / 100 ) ;
12
+ }
13
+ } else {
14
+ if ( brackets [ i - 1 ] ) {
15
+ a += ( income - brackets [ i - 1 ] [ 0 ] ) * ( brackets [ i ] [ 1 ] / 100 ) ;
16
+ } else a += income * ( brackets [ i ] [ 1 ] / 100 ) ;
17
+ return a ;
18
+ }
19
+ }
20
+ return a ;
21
+ }
22
+ export default calculateTax ;
You can’t perform that action at this time.
0 commit comments