[leetcode: Python]303. Range Sum Query
来源:互联网 发布:手机直播间源码 编辑:程序博客网 时间:2024/06/05 11:23
题目:
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.
Example:
Given nums = [-2, 0, 3, -5, 2, -1]
sumRange(0, 2) -> 1
sumRange(2, 5) -> -1
sumRange(0, 5) -> -3
Note:
You may assume that the array does not change.
There are many calls to sumRange function.
题意:
求子序列的和。
要求数组不可改变,对这个函数的调用很频繁,所以尽量优化时间复杂度。
方法一:性能69ms
class NumArray(object): def __init__(self, nums): """ :type nums: List[int] """ self.add = [0] for i in nums: self.add.append(self.add[-1] + i) def sumRange(self, i, j): """ :type i: int :type j: int :rtype: int """ return self.add[j+1] - self.add[i]# Your NumArray object will be instantiated and called as such:# obj = NumArray(nums)# param_1 = obj.sumRange(i,j)
0 0
- [leetcode: Python]303. Range Sum Query
- 303.[LeetCode]Range Sum Query
- LeetCode-303. Range Sum Query
- [LeetCode]303. Range Sum Query
- LeetCode#303. Range Sum Query
- leetcode 303. Range Sum Query
- [LeetCode]303. Range Sum Query
- LeetCode 303. Range Sum Query
- LeetCode 303. Range Sum Query
- LeetCode 303. Range Sum Query
- leetcode-303. Range Sum Query
- LeetCode 303. Range Sum Query
- leetcode.303.Range Sum Query
- leetcode 303. Range Sum Query
- leetcode 303. Range Sum Query
- [leetcode]: 303. Range Sum Query
- [Leetcode] 303. Range Sum Query
- [LeetCode]303. Range Sum Query
- python 编码
- quartusII 11.0 64位破解不完全问题解决办法
- java中程序计时
- Hibernate_二级缓存3_使用EHCache缓存
- hdu1754 线段树
- [leetcode: Python]303. Range Sum Query
- Windows学习(002)--Windows基础数据类型
- 【思想感悟】站在巨人的肩膀上
- HDU2881 Jack's struggle (LIS)
- ES6 Javascript
- (11)关卡编辑器之细节列表
- HDU 1259
- 2017年华东师范大学网络赛 E
- 反幻方 题目