File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
solution/0600-0699/0643.Maximum Average Subarray I Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change @@ -121,6 +121,30 @@ impl Solution {
121
121
}
122
122
```
123
123
124
+ ### ** PHP**
125
+
126
+ ``` php
127
+ class Solution {
128
+ /**
129
+ * @param Integer[] $nums
130
+ * @param Integer $k
131
+ * @return Float
132
+ */
133
+ function findMaxAverage($nums, $k) {
134
+ $sum = 0;
135
+ for ($i = 0; $i < $k; $i++) {
136
+ $sum += $nums[$i];
137
+ }
138
+ $max = $sum;
139
+ for ($j = $k; $j < count($nums); $j++) {
140
+ $sum = $sum - $nums[$j - $k] + $nums[$j];
141
+ $max = max($max, $sum);
142
+ }
143
+ return $max / $k;
144
+ }
145
+ }
146
+ ```
147
+
124
148
### ** ...**
125
149
126
150
```
Original file line number Diff line number Diff line change @@ -109,6 +109,30 @@ impl Solution {
109
109
}
110
110
```
111
111
112
+ ### ** PHP**
113
+
114
+ ``` php
115
+ class Solution {
116
+ /**
117
+ * @param Integer[] $nums
118
+ * @param Integer $k
119
+ * @return Float
120
+ */
121
+ function findMaxAverage($nums, $k) {
122
+ $sum = 0;
123
+ for ($i = 0; $i < $k; $i++) {
124
+ $sum += $nums[$i];
125
+ }
126
+ $max = $sum;
127
+ for ($j = $k; $j < count($nums); $j++) {
128
+ $sum = $sum - $nums[$j - $k] + $nums[$j];
129
+ $max = max($max, $sum);
130
+ }
131
+ return $max / $k;
132
+ }
133
+ }
134
+ ```
135
+
112
136
### ** ...**
113
137
114
138
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param Integer[] $nums
4
+ * @param Integer $k
5
+ * @return Float
6
+ */
7
+ function findMaxAverage ($nums , $k ) {
8
+ $sum = 0 ;
9
+ for ($i = 0 ; $i < $k ; $i ++ ) {
10
+ $sum += $nums [$i ];
11
+ }
12
+ $max = $sum ;
13
+ for ($j = $k ; $j < count ($nums ); $j ++ ) {
14
+ $sum = $sum - $nums [$j - $k ] + $nums [$j ];
15
+ $max = max ($max , $sum );
16
+ }
17
+ return $max / $k ;
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments