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

Commitc17d7ef

Browse files
authored
Merge pull request#3154 from PavanCheruvupally/patch-1
Create 1572-matrix-diagonal-sum.py
2 parents28e9b32 +763318e commitc17d7ef

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎python/1572-matrix-diagonal-sum.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
classSolution:
3+
defPrimeSum(self,mat):
4+
cnt=0
5+
foriinrange(len(mat)):
6+
cnt+=mat[i][i]
7+
returncnt
8+
9+
defCrossSum(self,mat):
10+
cnt=0
11+
foriinrange(len(mat)):
12+
cnt+=mat[i][len(mat)-i-1]
13+
returncnt
14+
15+
defdiagonalSum(self,mat:List[List[int]])->int:
16+
prime=self.PrimeSum(mat)
17+
cross=self.CrossSum(mat)
18+
19+
iflen(mat)%2==0:
20+
returnprime+cross
21+
else:
22+
mid=len(mat)//2
23+
mid_ele=mat[mid][mid]
24+
returnprime+cross-mid_ele

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp