File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
product-of-array-except-self Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ # ๊ฐ ์ธ๋ฑ์ค ๊ธฐ์ค ์ผ์ชฝ์ ์๋ ๊ฐ๋ค์ ๊ณฑ์ l_arr ์ ์ ์ฅํ๋ค.
2+ # ๊ฐ ์ธ๋ฑ์ค ๊ธฐ์ค ์ค๋ฅธ์ชฝ์ ์๋ ๊ฐ๋ค์ ๊ณฑ์ r_arr ์ ์ ์ฅํ๋ค.
3+ # ๋ง์ง๋ง์ ๊ฐ์ ์ธ๋ฑ์ค์ l_arr ๊ฐ๊ณผ r_arr ๊ฐ์ ๊ณฑํด์
4+ # => ํด๋น ์ธ๋ฑ์ค๋ฅผ ์ ์ธํ ๋ชจ๋ ์์์ ๊ณฑ์ ๊ตฌํ๋ค.
5+ class Solution :
6+ def productExceptSelf (self , nums : List [int ]) -> List [int ]:
7+ n = len (nums )
8+ l_arr = [0 ] * n # ์ผ์ชฝ ๋์ ๊ณฑ
9+ r_arr = [0 ] * n # ์ค๋ฅธ์ชฝ ๋์ ๊ณฑ
10+
11+ l_mult = 1
12+ r_mult = 1
13+
14+ for i in range (n ):
15+ j = - i - 1
16+ l_arr [i ] = l_mult
17+ r_arr [j ] = r_mult
18+ l_mult *= nums [i ]
19+ r_mult *= nums [j ]
20+
21+ return [ l * r for l , r in zip (l_arr , r_arr )]
You canโt perform that action at this time.
0 commit comments