MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / sumRange

Method sumRange

Java/Range-Sum-Query-Mutable.java:55–74  ·  view source on GitHub ↗
(int l, int r)

Source from the content-addressed store, hash-verified

53
54 // this is responsible for the sum betweeen given ranges
55 public int sumRange(int l, int r) {
56 // get leaf with value 'l'
57 l += n;
58 // get leaf with value 'r'
59 r += n;
60 int sum = 0;
61 while (l <= r) {
62 if ((l % 2) == 1) {
63 sum += tree[l];
64 l++;
65 }
66 if ((r % 2) == 0) {
67 sum += tree[r];
68 r--;
69 }
70 l /= 2;
71 r /= 2;
72 }
73 return sum;
74 }
75
76
77}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected