[LeetCode]Arithmetic Slices

Slowly....

class Solution {  
public:  
    int numberOfArithmeticSlices(vector<int>& A) {
        if(A.size() <= 2) {
            return 0;
        }

        int result = 0;
        int *diff = new int[A.size() - 1];
        int i, j;
        vector<int> m;
        m.push_back(0);

        for(i = 0; i < A.size() - 1; i++) {
            diff[i] = A[i + 1] - A[i];
        }

        int tmp = 0;
        for(i = 0; i < A.size() - 2; i++) {
            if(diff[i + 1] == diff[i]) {
                tmp++;
            } else {
                tmp++;
                for(j = m.size(); j < tmp + 2; j++) {
                    m.push_back(m[j - 1] + j - 1);
                }
                result += m[tmp];
                tmp = 0;
            }
        }

        tmp++;
        for(j = m.size(); j < tmp + 2; j++) {
            m.push_back(m[j - 1] + j - 1);
        }
        result += m[tmp];

        return result;
    }
};