@Matt.X.Zhao Hi I like your solution very much! There are lesser cases to handle.

Besides I want to know the time complexity of this solution. In my opinion, although we only proceed comparing when the character at position i is different (which will only happens once), the worst case is still O(n) since the position can be n.

Am I thinking right? Thanks!