<jupyter_start><jupyter_text>LeetCode 896. Monotonic Array Question    https://leetcode.com/problems/monotonic-array/    An array is monotonic if it is either monotone increasing or monotone decreasing.    An array A is monotone increasing if for all i = A[j].    Return true if and only if the given array A is monotonic.Example 1:    Input: [1,2,2,3]    Output: trueExample 2:    Input: [6,5,4,4]    Output: trueExample 3:    Input: [1,3,2]    Output: falseExample 4:    Input: [1,2,4,5]    Output: trueExample 5:    Input: [1,1,1]    Output: true   Note:    1 <= A.length <= 50000    -100000 <= A[i] <= 100000  My Solution<jupyter_code>def isMonotonic(A):
    if A == sorted(A) or A == sorted(A, reverse=True):
        return True 
    return False
# test code
A = [1,3,2]
isMonotonic(A)<jupyter_output><empty_output><jupyter_text>My Result__Runtime__ : 588 ms, faster than 24.47% of Python3 online submissions for Monotonic Array.__Memory Usage__ : 20 MB, less than 5.26% of Python3 online submissions for Monotonic Array.  @cslzy's Solution<jupyter_code>def isMonotonic(A):
    n = len(A)
    
    ### 길이가 2 이하면 True
    if n <= 2: return True
    
    ### 스위치 두 개를 설정
    isGreat = False
    isLess = False
    for i in range(1, n):
        
        ## 앞의 숫자가 큰 게 있을 경우 isGreat 스위치를 True로 켭니다.
        if A[i - 1] > A[i]:
            isGreat = True
            
        ## 뒤의 숫자가 큰 경우가 있을 경우 isLess 스위치를 True로 켭니다.
        if A[i - 1] < A[i]:
            isLess = True

        ## 두 스위치가 모두 켜져 있다면 False를 반환합니다.
        if isGreat and isLess:
            return False
    
    ## 두 스위치가 모두 켜지지 않는다면 True를 반환합니다.
    return True
# test code
A = [1,3,2]
isMonotonic(A)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10340775558166862, 'fraction_numerical': 0.04054054054054054, 'mean_word_length': 2.518595041322314, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 10, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '60553', 'license': 'MIT', 'n_tokens_mistral': 729, 'n_tokens_neox': 709, 'n_words': 205, 'path': 'LeetCode/LeetCode_896MonotonicArray.ipynb', 'repo_name': 'foxsayy/python', 'size': '1702'}