Skip to content

Commit 7b3b288

Browse files
committed
solutions: 0525 - Contiguous Array (Medium)
1 parent b038047 commit 7b3b288

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

solutions/0500-0599/0525-contiguous-array-medium.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
description: 'Author: @wingkwong | https://leetcode.com/problems/contiguous-array/'
3+
tags: [Array, Hash Table, Prefix Sum]
34
---
45

56
# 0525 - Contiguous Array (Medium)
@@ -41,6 +42,8 @@ For example, given the input $$[0, 0, 0, 1, 1, 1]$$, $$pre$$ would be 0 -> -1 ->
4142

4243
Therefore, the approach is to calculate the prefix sum and put it into a hash map. If the prefix sum can be found, then the we can compare the length with the current maximum answer to see if we update it or not. This solution gives both $$O(n)$$time complexity and space complexity.
4344

45+
<Tabs>
46+
<TabItem value="cpp" label="C++">
4447
<SolutionAuthor name="@wingkwong"/>
4548

4649
```cpp
@@ -60,8 +63,15 @@ public:
6063
};
6164
```
6265
66+
</TabItem>
67+
</Tabs>
68+
6369
Or you can initialise $$m[pre] = -1$$ for $$pre = 0$$.
6470
71+
<Tabs>
72+
<TabItem value="cpp" label="C++">
73+
<SolutionAuthor name="@wingkwong"/>
74+
6575
```cpp
6676
class Solution {
6777
public:
@@ -78,3 +88,6 @@ public:
7888
}
7989
};
8090
```
91+
92+
</TabItem>
93+
</Tabs>

0 commit comments

Comments
 (0)