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

Commit 6ca6233

Browse files
update solutions
1 parent 64845f4 commit 6ca6233

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

‎数组/48. 旋转图像.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ class Solution:
8383
"""
8484
Do not return anything, modify matrix in-place instead.
8585
"""
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):
9190
for j in range(i):
9291
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
93-
```
92+
return matrix
93+
94+
95+
96+
9497

‎数组/495. 提莫攻击.md‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@
3333
```python
3434
class Solution:
3535
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
4542
```
4643

4744
Tips

‎数组总结.md‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,13 @@ class Solution:
787787
"""
788788
Do not return anything, modify matrix in-place instead.
789789
"""
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):
795794
for j in range(i):
796795
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
796+
return matrix
797797
```
798798

799799

@@ -928,15 +928,12 @@ Tips
928928
```python
929929
class Solution:
930930
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
940937
```
941938

942939
Tips

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /