Problem0307

package
v0.0.0-...-4e682c9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2018 License: MIT Imports: 0 Imported by: 0

README

307. Range Sum Query - Mutable

题目

Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.

The update(i, val) function modifies nums by updating the element at index i to val.

Example:

Given nums = [1, 3, 5]

sumRange(0, 2) -> 9
update(1, 2)
sumRange(0, 2) -> 8

Note:

  1. The array is only modifiable by the update function.
  2. You may assume the number of calls to update and sumRange function is distributed evenly.

解题思路

见程序注释

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NumArray

type NumArray struct {
	// contains filtered or unexported fields
}

NumArray 是 nums 的和的切片

func Constructor

func Constructor(nums []int) NumArray

Constructor 返回 NumArray

func (*NumArray) SumRange

func (na *NumArray) SumRange(i int, j int) int

SumRange 返回 sum(nums[i:j+1])

func (*NumArray) Update

func (na *NumArray) Update(i int, v int)

Update 更新 nums

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL