I find a solution is better than mine to deal with this problem. However, when read his code carefully, I am not sure that if the problem can be solved totally by the code. Therefore, I copy the code to leetcode, and it is accepted. But I still feel puzzled, which leads me to make a test code, such as [8,8,7,7,6,7,5]. the expected reasult of this test case is 5. Apparently it is not. So maybe this test case can be added?
Add new test case [8,8,7,7,6,7,5]
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.