Leetcode Problem 1750. Minimum Length of String After Deleting Similar Ends

1750. Minimum Length of String After Deleting Similar Ends

Leetcode Solutions

Two Pointers Approach

  1. Initialize two pointers, left at 0 and right at the length of the string minus 1.
  2. While left is less than right: a. If the characters at left and right are different, break the loop. b. Store the character at left in a variable c. c. Increment left while the next character is the same as c. d. Decrement right while the previous character is the same as c and left is not greater than right.
  3. Return the length of the substring from left to right, which is right - left + 1.
UML Thumbnail

Brute Force Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...