Click here to see the full article post
Here is another solution: All we need to do is to check if the difference of each element ant its index is at most one.
@bangbangbear explaination and code in approach 3 is more easy to understand
@awice, I read this article from solution page, and the problem description is not matched with the solution. I think the problem description is for "Basic Calculator III".
Wrong problem description @awice
Nice solutions. The hardest part of this problem is understanding the problem statement.
About comment of solution 1:
A global inversion is also a local inversion. => wrong
A local inversion is also a global inversion. => correct
@zhangyuan_cau Thanks, corrected
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.