Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit32602e4

Browse files
Create 629.py
1 parentb0d8f65 commit32602e4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎501-1000/629.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
classSolution:
2+
defkInversePairs(self,n:int,k:int)->int:
3+
M=10**9+7
4+
d= [0]+ [1]* (k+1)
5+
forninrange(2,n+1):
6+
new= [0]
7+
forkinrange(k+1):
8+
v=d[k+1]
9+
v-=d[k-n+1]ifk>=nelse0
10+
new.append( (new[-1]+v)%M )
11+
d=new
12+
return (d[k+1]-d[k])%M

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp