Skip to content

Commit a63bb95

Browse files
committed
09/06
1 parent 151ee56 commit a63bb95

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Feel free to add issues, comment and pull request.
5757
| Leetcode | [359. Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter/description/) | [Java](./java/shouldPrintMessage.java) \| [Python](./Python/) | _O(n)_ | _O(n)_ | Easy | |
5858
| Leetcode | [535. Encode and Decode TinyURL](https://leetcode.com/problems/encode-and-decode-tinyurl/description/) | [Java](./java/Codec.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Medium | |
5959
| Leetcode | [266. Palindrome Permutation](https://leetcode.com/problems/palindrome-permutation/description/) | [Java](./java/canPermutePalindrome.java) \| [Python](./Python/) | _O(n)_ | _O(1)_ | Easy | |
60-
60+
| Leetcode | [525. Contiguous Array](https://leetcode.com/problems/contiguous-array/description/) | [Java](./java/FindMaxLength.java) \| [Python](./Python/) | _O( )_ | _O( )_ | Medium | |
6161

6262

6363
## Trees

java/FindMaxLength.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public int findMaxLength(int[] nums) {
3+
4+
if(nums.length == 0)
5+
return 0;
6+
7+
HashMap<Integer, Integer> sumToMax = new HashMap<>();
8+
9+
for(int i = 0; i < nums.length; i++)
10+
if(nums[i]==0) nums[i] = -1;
11+
12+
int max = 0, sum = 0;
13+
14+
sumToMax.put(0, -1);
15+
16+
for(int i=0; i<nums.length; i++)
17+
{
18+
sum += nums[i];
19+
if(sumToMax.containsKey(sum))
20+
max = Math.max(max, i - sumToMax.get(sum));
21+
else
22+
sumToMax.put(sum,i);
23+
}
24+
25+
return max;
26+
27+
}
28+
}

triangleNumber.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)