Skip to content

Commit b4d04d3

Browse files
committed
Time: 23 ms (80.05%), Space: 55.1 MB (42.69%) - LeetHub
1 parent a471bae commit b4d04d3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int findMaxLength(int[] nums) {
3+
HashMap<Integer,Integer> map=new HashMap();
4+
map.put(0,-1);
5+
int sum=0,ans=0;
6+
for(int i=0;i<nums.length;i++){
7+
if(nums[i]==0) sum-=1;
8+
else sum+=1;
9+
if(map.containsKey(sum)) ans=Math.max(ans,i-map.get(sum));
10+
else map.put(sum,i);
11+
}
12+
return ans;
13+
}
14+
}

0 commit comments

Comments
 (0)