File tree 1 file changed +44
-0
lines changed 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -1065,6 +1065,10 @@ class Solution:
1065
1065
1066
1066
动态规划前缀和。
1067
1067
1068
+ <!-- tabs:start -->
1069
+
1070
+ #### ** Python**
1071
+
1068
1072
``` python
1069
1073
class NumArray :
1070
1074
@@ -1090,6 +1094,46 @@ class NumArray:
1090
1094
# param_1 = obj.sumRange(i,j)
1091
1095
```
1092
1096
1097
+ #### ** Go**
1098
+
1099
+ ``` go
1100
+ type NumArray struct {
1101
+ sums []int
1102
+ }
1103
+
1104
+
1105
+ func Constructor (nums []int ) NumArray {
1106
+ length := len (nums)
1107
+ sums := make ([]int , length)
1108
+ for i , num := range nums {
1109
+ if i == 0 {
1110
+ sums[i] = num
1111
+ } else {
1112
+ sums[i] = sums[i - 1 ] + num
1113
+ }
1114
+ }
1115
+ return NumArray{sums}
1116
+ }
1117
+
1118
+
1119
+ func (this *NumArray ) SumRange (i int , j int ) int {
1120
+ if i == 0 {
1121
+ return this.sums [j]
1122
+ } else {
1123
+ return this.sums [j] - this.sums [i - 1 ]
1124
+ }
1125
+ }
1126
+
1127
+
1128
+ /* *
1129
+ * Your NumArray object will be instantiated and called as such:
1130
+ * obj := Constructor(nums);
1131
+ * param_1 := obj.SumRange(i,j);
1132
+ */
1133
+ ```
1134
+
1135
+ <!-- tabs:end -->
1136
+
1093
1137
## 309. 最佳买卖股票时机含冷冻期
1094
1138
1095
1139
[ 原题链接] ( https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/ )
You can’t perform that action at this time.
0 commit comments