I don't understand why I am wrong.

  • 0

    This code if run with my algorithm is true. But when I submit, It is not true. Why? :( Help me.
    *class Solution {


    bool increasingTriplet(vector<int>& nums) {
        vector <int> L, R; 
        int n = nums.size();
        if (!n) return false;
        L.push_back(nums[0]); R.push_back(nums[n-1]);
        for (int i=1; i<n; i++)
            L.push_back(min(L[i-1], nums[i]));
        for (int i=n-1; i>=0; i--)
            R.push_back(max(R[i-1], nums[i]));
        for (int i=0; i<n/2; i++) swap(R[i], R[n-i-1]);
        for (int i=1; i<n-1; i++)
            if (nums[i]>L[i-1]&&nums[i]<R[i+1]) return true;
        return false;


Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.