aboutsummaryrefslogtreecommitdiff
path: root/arithmetic_slices2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'arithmetic_slices2.cpp')
-rw-r--r--arithmetic_slices2.cpp35
1 files changed, 0 insertions, 35 deletions
diff --git a/arithmetic_slices2.cpp b/arithmetic_slices2.cpp
deleted file mode 100644
index 8dd553c..0000000
--- a/arithmetic_slices2.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "leetcode.h"
-
-class Solution {
-public:
- int numberOfArithmeticSlices(vector<int> &nums) {
- unordered_map<int, vector<int>> num_idx;
- vvd(int) dp(nums.size(), vector<int>(nums.size()));
- int ans = 0;
- for (auto i = 0; i < nums.size(); ++i)
- num_idx[nums[i]].push_back(i);
- for (auto i = 0; i < nums.size(); ++i) {
- for (int j = 0; j < i; j++) {
- auto prev = 2l * nums[j] - nums[i];
- if (prev < INT_MIN || prev > INT_MAX)
- continue;
- auto it = num_idx.find(prev);
- if (it != end(num_idx)) {
- for (auto k : it->second) {
- if (k >= j)
- break;
- dp[i][j] += dp[j][k] + 1;
- }
- }
- ans += dp[i][j];
- }
- }
- return ans;
- }
-};
-
-int main() {
- Solution obj;
- vector<int> nums = {2, 4, 6, 8, 10};
- cout << obj.numberOfArithmeticSlices(nums);
-}