Range Sum Query - Immutable
https://leetcode.com/problems/range-sum-query-immutable/description/
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
Thoughts
这里用到一个常用的小trick, 求数组某段的和相当于总和减去前面的和。
Code
Analysis
时间复杂度为一次遍历,O(n)
Last updated
Was this helpful?