File tree 3 files changed +26
-29
lines changed
3 files changed +26
-29
lines changed Original file line number Diff line number Diff line change @@ -83,12 +83,15 @@ class Solution:
83
83
"""
84
84
Do not return anything, modify matrix in-place instead.
85
85
"""
86
- n= len (matrix)
87
- for i in range (n// 2 ):
88
- for j in range (n):
89
- matrix[i][j] ,matrix[n- 1 - i][j]= matrix[n- 1 - i][j], matrix[i][j]
90
- for i in range (n):
86
+ nrow = len (matrix)
87
+ for i in range (nrow// 2 ):
88
+ matrix[i][:],matrix[nrow- 1 - i][:] = matrix[nrow- 1 - i][:], matrix[i][:]
89
+ for i in range (nrow):
91
90
for j in range (i):
92
91
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
93
- ```
92
+ return matrix
93
+
94
+
95
+
96
+
94
97
Original file line number Diff line number Diff line change 33
33
``` python
34
34
class Solution :
35
35
def findPoisonedDuration (self , timeSeries : List[int ], duration : int ) -> int :
36
- harm = duration
37
- pos = timeSeries[0 ]+ duration
38
- for i in timeSeries[1 :]:
39
- if pos> i:
40
- harm += i+ duration- pos
41
- else :
42
- harm+= duration
43
- pos = i+ duration
44
- return harm
36
+ total = 0
37
+ pre = 0
38
+ for i in range (len (timeSeries)):
39
+ total += max (duration - max (pre- timeSeries[i],0 ),0 )
40
+ pre = timeSeries[i]+ duration
41
+ return total
45
42
```
46
43
47
44
Tips
Original file line number Diff line number Diff line change @@ -787,13 +787,13 @@ class Solution:
787
787
"""
788
788
Do not return anything, modify matrix in-place instead.
789
789
"""
790
- n= len (matrix)
791
- for i in range (n// 2 ):
792
- for j in range (n):
793
- matrix[i][j] ,matrix[n- 1 - i][j]= matrix[n- 1 - i][j], matrix[i][j]
794
- for i in range (n):
790
+ nrow = len (matrix)
791
+ for i in range (nrow// 2 ):
792
+ matrix[i][:],matrix[nrow- 1 - i][:] = matrix[nrow- 1 - i][:], matrix[i][:]
793
+ for i in range (nrow):
795
794
for j in range (i):
796
795
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
796
+ return matrix
797
797
```
798
798
799
799
@@ -928,15 +928,12 @@ Tips
928
928
``` python
929
929
class Solution :
930
930
def findPoisonedDuration (self , timeSeries : List[int ], duration : int ) -> int :
931
- harm = duration
932
- pos = timeSeries[0 ]+ duration
933
- for i in timeSeries[1 :]:
934
- if pos> i:
935
- harm += i+ duration- pos
936
- else :
937
- harm+= duration
938
- pos = i+ duration
939
- return harm
931
+ total = 0
932
+ pre = 0
933
+ for i in range (len (timeSeries)):
934
+ total += max (duration - max (pre- timeSeries[i],0 ),0 )
935
+ pre = timeSeries[i]+ duration
936
+ return total
940
937
```
941
938
942
939
Tips
You can’t perform that action at this time.
0 commit comments