MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / buildTree

Method buildTree

java/0307-range-sum-query-mutable.java:12–20  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

10
11 // O(n)
12 private void buildTree(int[] nums) {
13 // we build the tree from bottom up
14 for (int i = n, j = 0; i < 2 * this.n; i++, j++) {
15 this.tree[i] = nums[j];
16 }
17 for (int i = this.n-1; i > 0; i--) {
18 this.tree[i] = this.tree[2 * i] + this.tree[2 * i + 1]; // parent value is sum of children values
19 }
20 }
21
22 // O(logn)
23 public void update(int index, int val) {

Callers 1

NumArrayMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected