Range Sum Query Immutable - Leetcode 303 - Python

preview_player
Показать описание


0:00 - Read the problem
0:30 - Drawing Explanation
5:55 - Coding Explanation

leetcode 303

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

A trick I like to use for the prefix array is to subtract left and add nums[left] instead of going one position over so we don't have to worry about boundary check, for example: prefix[right] - prefix[left] + nums[left]

cesarfa-bt
Автор

2:00 Why O(n^2)?
O(n^2) is the time complexity of finding pairs.
Intuitively the time complexity is greater to find every subarray

flatmapper
Автор

what if left = 0, right = 0; -2 + (-2)

MianyunNi
Автор

You wrote left > 0 then but as index, left can be 0 to indicate first index

mehedihassan-pfyh