[LeetCode]Wiggle Subsequence

O(n^2):

class Solution {  
public:  
    int wiggleMaxLength(vector<int>& nums) {
        if(nums.size() <= 1) {
            return nums.size();
        }

        int tmp, localsum;
        vector<int> dpp(nums.size());
        vector<int> dpn(nums.size());
        dpp[0] = 1;
        dpn[0] = 1;

        for(int i = 1; i < nums.size(); i++) {
            for(int j = 0; j < i; j++) {
                tmp = nums[i] - nums[j];
                if(tmp > 0) {
                    localsum = dpn[j] + 1;
                    if(localsum > dpp[i]) {
                        dpp[i] = localsum;
                    }
                } else if(tmp < 0) {
                    localsum = dpp[j] + 1;
                    if(localsum > dpn[i]) {
                        dpn[i] = localsum;
                    }
                } else {
                    dpp[i] = dpp[j];
                    dpn[i] = dpn[j];
                }
            }
        }

        return max(dpp.back(), dpn.back());
    }
};

There should be a way of O(n).Try to find it.