Categorygithub.com/ductnn/coding-practiceleetcode1750.MinimumLengthofStringAfterDeletingSimilarEnds
package
0.0.0-20241225161807-6c2a4c2dbe8f
Repository: https://github.com/ductnn/coding-practice.git
Documentation: pkg.go.dev

# README

1750. Minimum Length of String After Deleting Similar Ends

Solutions

Solution 1: Two pointers

Define two pointers $i$ and $j$ to point to the head and tail of the string $s$ respectively, then move them to the middle until the characters pointed to by $i$ and $j$ are not equal

=> $\max(0, j - i + 1)$ is the answer.

The time complexity is $O(n)$ and the space complexity is $O(1)$. Where $n$ is the length of the string $s$.