Skip to content

Commit 9feafac

Browse files
committed
🟢 Solve problem 1512
1 parent 5b086e3 commit 9feafac

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

‎.vscode/settings.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"python.testing.unittestArgs": [
3+
"-v",
4+
"-s",
5+
"./python",
6+
"-p",
7+
"*test.py"
8+
],
9+
"python.testing.pytestEnabled": false,
10+
"python.testing.unittestEnabled": true
11+
}

‎python/1512.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
3+
class Solution:
4+
def numIdenticalPairs(self, nums: list[int]) -> int:
5+
results = []
6+
result = 0
7+
8+
for i in range(len(nums)):
9+
for j in range(i + 1, len(nums)):
10+
if nums[i] == nums[j]:
11+
results.append((i, j))
12+
13+
for _ in results:
14+
result += 1
15+
16+
return result
17+
18+
class TestNumIdenticalPairs(unittest.TestCase):
19+
def setUp(self):
20+
self.sol = Solution()
21+
22+
def testNumIdenticalPairs(self):
23+
self.assertEqual(self.sol.numIdenticalPairs([1, 2, 3, 1, 1, 3]), 4,
24+
"Erro: esperado 4 pares bons para a lista [1, 2, 3, 1, 1, 3]")
25+
self.assertEqual(self.sol.numIdenticalPairs([1, 1, 1, 1]), 6,
26+
"Erro: esperado 6 pares bons para a lista [1, 1, 1, 1]")
27+
self.assertEqual(self.sol.numIdenticalPairs([1, 2, 3]), 0,
28+
"Erro: esperado 0 pares bons para a lista [1, 2, 3]")
29+
30+
if __name__ == '__main__':
31+
unittest.main()

0 commit comments

Comments
 (0)