当前位置:网站首页>Leetcode: Sword finger offer 66 Build product array [application of pre and post infix]
Leetcode: Sword finger offer 66 Build product array [application of pre and post infix]
2022-06-12 06:36:00 【Review of the white speed Dragon King】

analysis
Because you can't use a division sign
So we should consider saving the front and back infix
And make a special judgment , Other normal calculations are sufficient
Be careful None and 【】
ac code
class Solution:
def constructArr(self, a: List[int]) -> List[int]:
if not a:
return []
n = len(a)
b = a[::-1]
preMul, postMul = [0] * n, [0] * n
preMul[0] = a[0]
for i in range(1, n):
preMul[i] = preMul[i - 1] * a[i]
postMul[0] = b[0]
for i in range(1, n):
postMul[i] = postMul[i - 1] * b[i]
ans = []
for i in range(n):
if i == 0:
ans.append(postMul[n - 2])
elif i == n - 1:
ans.append(preMul[n - 2])
else:
ans.append(preMul[i - 1] * postMul[n - i - 2])
return ans
summary
Anteroposterior accretion
边栏推荐
- Highlight detection with pairwise deep ranking for first person video summary (thesis translation)
- PDF. js FAQs
- LeetCode-1350. Invalid students
- Reentrantlock underlying AQS source code analysis
- Opencv_100问_第五章 (21-25)
- torch在高版本训练的模型在低版本中使用报错
- 张驰课堂:2022年CAQ中质协六西格玛考试时间通知
- The first principle of thinking method
- SQL注入原理即sqli-labs搭建,sql注入简单实战
- Apache POI import export excel file
猜你喜欢

Qt-- realize TCP communication

Jetson TX2 machine brushing jetpack4.2 (self test successful version)

Solution: content type 'application/x-www-form-urlencoded; charset=UTF-8‘ not supported

SQL 注入-盲注

leetcode:剑指 Offer 67. 把字符串转换成整数【模拟 + 分割 +讨论】

Leetcode personal question solution (Sword finger offer3-5) 3 Duplicate number in array, 4 Find in 2D array, 5 Replace spaces

PHP read / write cookie

Codeforces Round #793 (Div. 2) A B C

LeetCode-419. Battleship on deck

SQL injection based on error reporting
随机推荐
LeetCode-1490. Clone n-ary tree
Deep and detailed analysis of PHP one sentence Trojan horse
Delete the duplicate items in the ordered array -- force deduction question 26 (simple)
Qt-- realize TCP communication
Redis distributed lock
SQL 注入-盲注
Leetcode January 10 daily question 306 Additive number
leetcode 278. First wrong version
LeetCode-419. Battleship on deck
六月集训 第九日——位运算
JS pre parsing
The principle of SQL injection is to build sqli labs, and SQL injection is simple and practical
Leetcode January 13 daily question 747 At least twice the maximum number of other numbers
Highlight detection with pairwise deep ranking for first person video summary (thesis translation)
Zhang Chi: is process a panacea?
[word] word 2010 recording macro batch replacing paragraph marks in the selected text
SQL 注入读写文件
June 9th training day - bit operation
基于报错的 SQL 注入
The first day of June training - array