Skip to content

Commit d2e41ff

Browse files
committed
returning
1 parent e3bcac8 commit d2e41ff

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import collections
2+
from typing import List
3+
4+
5+
# leetcode submit region begin(Prohibit modification and deletion)
6+
class Solution:
7+
def countBadPairs(self, nums: List[int]) -> int:
8+
N = len(nums)
9+
seen = collections.defaultdict(set)
10+
good_pairs = 0
11+
12+
def sum_natural_numbers(n):
13+
return n * (n + 1) // 2
14+
15+
total_pairs = sum_natural_numbers(N - 1)
16+
for j in range(N):
17+
target = j
18+
if (nums[j] - target) in seen:
19+
new_target = j - (nums[j] - target)
20+
if new_target in seen[(nums[j] - target)]:
21+
good_pairs += 1
22+
seen[nums[j]].add(j)
23+
24+
return total_pairs - good_pairs
25+
26+
27+
# leetcode submit region end(Prohibit modification and deletion)
28+
29+
30+
class CountNumberOfBadPairs(Solution):
31+
pass

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from leetcode.editor.en.Q1462.CourseScheduleIv import CourseScheduleIv
1+
from leetcode.editor.en.Q2364.CountNumberOfBadPairs import CountNumberOfBadPairs
22

33
if __name__ == '__main__':
4-
print(CourseScheduleIv().checkIfPrerequisite(numCourses=2, prerequisites=[[1, 0]], queries=[[0, 1], [1, 0]]))
4+
print(CountNumberOfBadPairs().countBadPairs([0, 1, 2, 3, 4]))

0 commit comments

Comments
 (0)