C, 9ms O(n) solution

  • 0

    Reverse the array, and determine whether it is a Stack-sortable permutation.

    bool find132pattern(int* nums, int numsSize) {
        if (numsSize < 3)
            return false;
        static int stack[15000];
        int top = 0;
        int last = INT_MIN;
        while (numsSize--) {
            if (nums[numsSize] < last)
                return true;
            while (top&&stack[top-1]<nums[numsSize]) {
                last = stack[--top];
        return false;

Log in to reply

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