aboutsummaryrefslogtreecommitdiff
path: root/num_bad_pairs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'num_bad_pairs.cpp')
-rw-r--r--num_bad_pairs.cpp27
1 files changed, 0 insertions, 27 deletions
diff --git a/num_bad_pairs.cpp b/num_bad_pairs.cpp
deleted file mode 100644
index 75ea430..0000000
--- a/num_bad_pairs.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "leetcode.h"
-
-/*
- * given: 0-indexed integer array
- * bad pair: (i, j) if
- * i < j && j - i != nums[j] - nums[i]
- */
-
-class Solution {
-public:
- long long countBadPairs(vector<int> &nums) {
- long long ans = 0;
- unordered_map<int, int> um;
- for (int i = 0; i < nums.size(); ++i) {
- ans += (long long)i - um[nums[i] - i];
- ++um[nums[i] - i];
- }
- return ans;
- }
-};
-
-int main() {
- Solution obj;
- vector<int> nums1 = {4, 1, 3, 3}, nums2 = {1, 2, 3, 4, 5};
- cout << obj.countBadPairs(nums1) << endl; // expect: 5
- cout << obj.countBadPairs(nums2) << endl; // expect: 0
-}