<qiyuangong>581_Shortest_Unsorted_Continuous_Subarray_2.py
def findUnsortedSubarray( nums):
    stack = []
    l, r = len(nums), 0
    for i in range(len(nums)):
        while len(stack) != 0 and nums[stack[-1]] > nums[i]:
            l = min(l, stack.pop())
        stack.append(i)
    stack = []
    for i in range(len(nums) - 1, -1, -1):
        while len(stack) != 0 and nums[stack[-1]] < nums[i]:
            r = max(r, stack.pop())
        stack.append(i)
    if r > l:
        return r - l + 1
    return 0
def sample_funcname ( var_0 ) :
    var_1 = [ ]
    var_3 , var_5 = len ( var_0 ) , 0
    for var_7 in range ( len ( var_0 ) ) :
        while len ( var_1 ) != 0 and var_0 [ var_1 [ - 1 ] ] > var_0 [ var_7 ] :
            var_3 = min ( var_3 , var_1.pop ( ) )
        var_1.append ( var_7 )
    var_1 = [ ]
    for var_7 in range ( len ( var_0 ) - 1 , - 1 , - 1 ) :
        while len ( var_1 ) != 0 and var_0 [ var_1 [ - 1 ] ] < var_0 [ var_7 ] :
            var_5 = max ( var_5 , var_1.pop ( ) )
        var_1.append ( var_7 )
    if var_5 > var_3 :
        return var_5 - var_3 + 1
    return 0
