problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Private 属性 | 所有成员列表
leetcode::range_sum_query_immutable::NumArray类 参考

#include <leetcode.h>

Public 成员函数

 NumArray (vector< int > &nums)
 Initializes the object with the integer array nums. 更多...
 
int sumRange (int left, int right) const
 Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]). 更多...
 

Private 属性

vector< int > pref_sum
 

详细描述

在文件 leetcode.h2267 行定义.

构造及析构函数说明

◆ NumArray()

leetcode::range_sum_query_immutable::NumArray::NumArray ( vector< int > &  nums)
explicit

Initializes the object with the integer array nums.

在文件 leetcode.cpp6055 行定义.

6055 {
6056 pref_sum = vector<int>(nums.size());
6057 pref_sum[0] = nums[0];
6058 for(int i = 1; i < nums.size(); i++) {
6059 pref_sum[i] = pref_sum[i - 1] + nums[i];
6060 }
6061 }

引用了 pref_sum.

成员函数说明

◆ sumRange()

int leetcode::range_sum_query_immutable::NumArray::sumRange ( int  left,
int  right 
) const

Returns the sum of the elements of nums between indices left and right inclusive (i.e. nums[left] + nums[left + 1] + ... + nums[right]).

在文件 leetcode.cpp6063 行定义.

6063{ return pref_sum[right] - (left - 1 >= 0 ? pref_sum[left - 1] : 0); }

引用了 acwing::acwing1929::left, pref_sum , 以及 acwing::acwing1929::right.

类成员变量说明

◆ pref_sum

vector<int> leetcode::range_sum_query_immutable::NumArray::pref_sum
private

在文件 leetcode.h2268 行定义.

被这些函数引用 NumArray() , 以及 sumRange().


该类的文档由以下文件生成: