File tree 6 files changed +195
-0
lines changed
0011.Container With Most Water
6 files changed +195
-0
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,35 @@ public class Solution {
206
206
}
207
207
```
208
208
209
+ ``` php
210
+ class Solution {
211
+ /**
212
+ * @param int[] $height
213
+ * @return int
214
+ */
215
+
216
+ function maxArea($height) {
217
+ $left = 0;
218
+ $right = count($height) - 1;
219
+ $maxArea = 0;
220
+
221
+ while ($left < $right) {
222
+ $area = min($height[$left], $height[$right]) * ($right - $left);
223
+
224
+ $maxArea = max($maxArea, $area);
225
+
226
+ if ($height[$left] < $height[$right]) {
227
+ $left++;
228
+ } else {
229
+ $right--;
230
+ }
231
+ }
232
+
233
+ return $maxArea;
234
+ }
235
+ }
236
+ ```
237
+
209
238
<!-- tabs: end -->
210
239
211
240
<!-- end -->
Original file line number Diff line number Diff line change @@ -201,6 +201,35 @@ public class Solution {
201
201
}
202
202
```
203
203
204
+ ``` php
205
+ class Solution {
206
+ /**
207
+ * @param int[] $height
208
+ * @return int
209
+ */
210
+
211
+ function maxArea($height) {
212
+ $left = 0;
213
+ $right = count($height) - 1;
214
+ $maxArea = 0;
215
+
216
+ while ($left < $right) {
217
+ $area = min($height[$left], $height[$right]) * ($right - $left);
218
+
219
+ $maxArea = max($maxArea, $area);
220
+
221
+ if ($height[$left] < $height[$right]) {
222
+ $left++;
223
+ } else {
224
+ $right--;
225
+ }
226
+ }
227
+
228
+ return $maxArea;
229
+ }
230
+ }
231
+ ```
232
+
204
233
<!-- tabs: end -->
205
234
206
235
<!-- end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param int[] $height
4
+ * @return int
5
+ */
6
+
7
+ function maxArea ($height ) {
8
+ $left = 0 ;
9
+ $right = count ($height ) - 1 ;
10
+ $maxArea = 0 ;
11
+
12
+ while ($left < $right ) {
13
+ $area = min ($height [$left ], $height [$right ]) * ($right - $left );
14
+
15
+ $maxArea = max ($maxArea , $area );
16
+
17
+ if ($height [$left ] < $height [$right ]) {
18
+ $left ++ ;
19
+ } else {
20
+ $right -- ;
21
+ }
22
+ }
23
+
24
+ return $maxArea ;
25
+ }
26
+ }
Original file line number Diff line number Diff line change @@ -181,6 +181,44 @@ public class Solution {
181
181
}
182
182
```
183
183
184
+ ``` php
185
+ class Solution {
186
+ /**
187
+ * @param int $num
188
+ * @return string
189
+ */
190
+
191
+ function intToRoman($num) {
192
+ $values = [
193
+ 'M' => 1000,
194
+ 'CM' => 900,
195
+ 'D' => 500,
196
+ 'CD' => 400,
197
+ 'C' => 100,
198
+ 'XC' => 90,
199
+ 'L' => 50,
200
+ 'XL' => 40,
201
+ 'X' => 10,
202
+ 'IX' => 9,
203
+ 'V' => 5,
204
+ 'IV' => 4,
205
+ 'I' => 1,
206
+ ];
207
+
208
+ $result = '';
209
+
210
+ foreach ($values as $roman => $value) {
211
+ while ($num >= $value) {
212
+ $result .= $roman;
213
+ $num -= $value;
214
+ }
215
+ }
216
+
217
+ return $result;
218
+ }
219
+ }
220
+ ```
221
+
184
222
<!-- tabs: end -->
185
223
186
224
<!-- end -->
Original file line number Diff line number Diff line change @@ -168,6 +168,44 @@ public class Solution {
168
168
}
169
169
```
170
170
171
+ ``` php
172
+ class Solution {
173
+ /**
174
+ * @param int $num
175
+ * @return string
176
+ */
177
+
178
+ function intToRoman($num) {
179
+ $values = [
180
+ 'M' => 1000,
181
+ 'CM' => 900,
182
+ 'D' => 500,
183
+ 'CD' => 400,
184
+ 'C' => 100,
185
+ 'XC' => 90,
186
+ 'L' => 50,
187
+ 'XL' => 40,
188
+ 'X' => 10,
189
+ 'IX' => 9,
190
+ 'V' => 5,
191
+ 'IV' => 4,
192
+ 'I' => 1,
193
+ ];
194
+
195
+ $result = '';
196
+
197
+ foreach ($values as $roman => $value) {
198
+ while ($num >= $value) {
199
+ $result .= $roman;
200
+ $num -= $value;
201
+ }
202
+ }
203
+
204
+ return $result;
205
+ }
206
+ }
207
+ ```
208
+
171
209
<!-- tabs: end -->
172
210
173
211
<!-- end -->
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param int $num
4
+ * @return string
5
+ */
6
+
7
+ function intToRoman($num) {
8
+ $values = [
9
+ 'M' => 1000,
10
+ 'CM' => 900,
11
+ 'D' => 500,
12
+ 'CD' => 400,
13
+ 'C' => 100,
14
+ 'XC' => 90,
15
+ 'L' => 50,
16
+ 'XL' => 40,
17
+ 'X' => 10,
18
+ 'IX' => 9,
19
+ 'V' => 5,
20
+ 'IV' => 4,
21
+ 'I' => 1,
22
+ ];
23
+
24
+ $result = '';
25
+
26
+ foreach ($values as $roman => $value) {
27
+ while ($num >= $value) {
28
+ $result .= $roman;
29
+ $num -= $value;
30
+ }
31
+ }
32
+
33
+ return $result;
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments