mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-24 02:14:00 +08:00
Update solution 0307
This commit is contained in:
@ -12,9 +12,25 @@ func Test_Problem307(t *testing.T) {
|
||||
obj.Update(1, 2)
|
||||
fmt.Printf("obj = %v\n", obj)
|
||||
fmt.Printf("SumRange(0,2) = %v\n", obj.SumRange(0, 2))
|
||||
}
|
||||
|
||||
// SumRange define
|
||||
func (ma *NumArray) SumRange(i int, j int) int {
|
||||
return ma.st.Query(i, j)
|
||||
obj = Constructor307([]int{-1})
|
||||
fmt.Printf("obj = %v\n", obj)
|
||||
fmt.Printf("SumRange(0,2) = %v\n", obj.SumRange(0, 0))
|
||||
obj.Update(0, 1)
|
||||
fmt.Printf("obj = %v\n", obj)
|
||||
fmt.Printf("SumRange(0,2) = %v\n", obj.SumRange(0, 0))
|
||||
|
||||
obj = Constructor307([]int{7, 2, 7, 2, 0})
|
||||
fmt.Printf("obj = %v\n", obj)
|
||||
obj.Update(4, 6)
|
||||
obj.Update(0, 2)
|
||||
obj.Update(0, 9)
|
||||
fmt.Printf("SumRange(0,2) = %v\n", obj.SumRange(4, 4))
|
||||
obj.Update(3, 8)
|
||||
fmt.Printf("obj = %v\n", obj)
|
||||
fmt.Printf("SumRange(0,2) = %v\n", obj.SumRange(0, 4))
|
||||
obj.Update(4, 1)
|
||||
fmt.Printf("SumRange(0,2) = %v\n", obj.SumRange(0, 3))
|
||||
fmt.Printf("SumRange(0,2) = %v\n", obj.SumRange(0, 4))
|
||||
obj.Update(0, 4)
|
||||
}
|
||||
|
Reference in New Issue
Block a user