You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/2900-2999/2937.Make Three Strings Equal/README_EN.md
+66-3
Original file line number
Diff line number
Diff line change
@@ -37,30 +37,93 @@ It can be shown that there is no way to make them equal with less than two opera
37
37
38
38
## Solutions
39
39
40
+
**Solution 1: Enumeration**
41
+
42
+
According to the problem description, we know that if the three strings are equal after deleting characters, then they have a common prefix of length greater than $1$. Therefore, we can enumerate the position $i$ of the common prefix. If the three characters at the current index $i$ are not all equal, then the length of the common prefix is $i$. At this point, we check if $i$ is $0$. If it is, return $-1$. Otherwise, return $s - 3 \times i$, where $s$ is the sum of the lengths of the three strings.
43
+
44
+
The time complexity is $O(n)$, where $n$ is the minimum length of the three strings. The space complexity is $O(1)$.
0 commit comments