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

Commit9d4bcf7

Browse files
authored
Update 0238-product-of-array-except-self.py
Eliminating unneeded prefix variable
1 parent53ccafb commit9d4bcf7

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

‎python/0238-product-of-array-except-self.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ class Solution:
22
defproductExceptSelf(self,nums:List[int])->List[int]:
33
res= [1]* (len(nums))
44

5-
prefix=1
6-
foriinrange(len(nums)):
7-
res[i]=prefix
8-
prefix*=nums[i]
5+
foriinrange(1,len(nums)):
6+
res[i]=res[i-1]*nums[i-1]
97
postfix=1
108
foriinrange(len(nums)-1,-1,-1):
119
res[i]*=postfix

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp