Skip to content

Commit 4c6d637

Browse files
committed
D. J.:
- Added the leetcode problem and solution for 1304
1 parent 81b6597 commit 4c6d637

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
- [1137 N-th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number/description/)
282282
- [1143 Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence/description/)
283283
- [1218 Longest Arithmetic Subsequence of Given Difference](https://leetcode.com/problems/longest-arithmetic-subsequence-of-given-difference/description/)
284+
- [1304 Find N Unique Integers Sum up to Zero](https://leetcode.com/problems/find-n-unique-integers-sum-up-to-zero/description/)
284285
- [1312 Minimum Insertion Steps to Make a String Palindrome](https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/description/)
285286
- [1329 Sort the Matrix Diagonally](https://leetcode.com/problems/sort-the-matrix-diagonally/description/)
286287
- [1456 Maximum Number of Vowels in a Substring of Given Length](https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/description/)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
"""Base class for all LeetCode Problems."""
6+
7+
def sumZero(self, n: int) -> List[int]:
8+
"""
9+
Given an integer n, return any array containing n unique integers such that
10+
they add up to 0.
11+
"""
12+
res = []
13+
14+
if n % 2:
15+
res.append(0)
16+
17+
for i in range(1, n // 2 + 1):
18+
res.append(-i)
19+
res.append(i)
20+
21+
return res
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import List
2+
3+
import pytest
4+
5+
from awesome_python_leetcode._1304_find_n_unique_integers_sum_up_to_zero import Solution
6+
7+
8+
@pytest.mark.parametrize(
9+
argnames=["n", "expected"],
10+
argvalues=[
11+
(5, [0, -1, 1, -2, 2]),
12+
(3, [0, -1, 1]),
13+
(1, [0]),
14+
],
15+
)
16+
def test_func(n: int, expected: List[int]):
17+
"""Tests the solution of a LeetCode problem."""
18+
sum_zero = Solution().sumZero(n)
19+
assert sum_zero == expected

0 commit comments

Comments
 (0)