I have a little confusion. if our element is small than the next element, it means that the peak should be in the range [mid+1, left], I agree with this part. However, why the element is larger than the next element, the peak should be in range [right, mid] instead of [right,mid-1] ？

Of course I knew your code is correct and I did ran through your code with some small edge cases which is easy to have bugs. I am amazed about the delicacy of the else right=mid part. I wonder how you manage to think up that brilliant part.