We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c4a8f5 commit 7a60253Copy full SHA for 7a60253
Medium/525. Contiguous Array/solution.php
@@ -0,0 +1,38 @@
1
+<?php
2
+
3
+class Solution {
4
5
+ /**
6
+ * @param Integer[] $nums
7
+ * @return Integer
8
+ */
9
+ function findMaxLength(array $nums) {
10
+ $maxLength = 0;
11
+ $count = 0;
12
+ $hashMap = [0 => -1];
13
14
+ foreach($nums as $key=> $number) {
15
16
+ if ($number == 0) {
17
+ $count --;
18
+ } else{
19
+ $count ++;
20
+ }
21
22
+ if(array_key_exists($count,$hashMap)) {
23
+ $maxLength = max($maxLength,$key - $hashMap[$count]);
24
+ } else {
25
+ $hashMap[$count] = $key;
26
27
28
29
+ return $maxLength;
30
31
32
+}
33
34
35
+$solution = new Solution;
36
37
+echo $solution->findMaxLength([0,1,0]);
38
0 commit comments