Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 32602e4

Browse filesBrowse files
Create 629.py
1 parent b0d8f65 commit 32602e4
Copy full SHA for 32602e4

File tree

1 file changed

+12
-0
lines changed
Filter options

1 file changed

+12
-0
lines changed

‎501-1000/629.py

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def kInversePairs(self, n: int, k: int) -> int:
3+
M = 10**9 + 7
4+
d = [0] + [1] * (k + 1)
5+
for n in range(2, n+1):
6+
new = [0]
7+
for k in range(k+1):
8+
v = d[k+1]
9+
v -= d[k-n+1] if k >= n else 0
10+
new.append( (new[-1] + v) % M )
11+
d = new
12+
return (d[k+1] - d[k]) % M

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.