diff --git a/solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md b/solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md
index 8d526eeb8ab0c..f388eb431ea1b 100644
--- a/solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md
+++ b/solution/1200-1299/1289.Minimum Falling Path Sum II/README_EN.md
@@ -30,7 +30,7 @@ tags:
Input: grid = [[1,2,3],[4,5,6],[7,8,9]]
Output: 13
-Explanation:
+Explanation:
The possible falling paths are:
[1,5,9], [1,5,7], [1,6,7], [1,6,8],
[2,4,8], [2,4,9], [2,6,7], [2,6,8],
diff --git a/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/README.md b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/README.md
new file mode 100644
index 0000000000000..70fffe6cf40a2
--- /dev/null
+++ b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/README.md
@@ -0,0 +1,268 @@
+---
+comments: true
+difficulty: 中等
+edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3460.Longest%20Common%20Prefix%20After%20at%20Most%20One%20Removal/README.md
+---
+
+
+
+# [3460. Longest Common Prefix After at Most One Removal 🔒](https://leetcode.cn/problems/longest-common-prefix-after-at-most-one-removal)
+
+[English Version](/solution/3400-3499/3460.Longest%20Common%20Prefix%20After%20at%20Most%20One%20Removal/README_EN.md)
+
+## 题目描述
+
+
+
+You are given two strings s
and t
.
+
+Return the length of the longest common prefix between s
and t
after removing at most one character from s
.
+
+Note: s
can be left without any removal.
+
+
+Example 1:
+
+
+
Input: s = "madxa", t = "madam"
+
+
Output: 4
+
+
Explanation:
+
+
Removing s[3]
from s
results in "mada"
, which has a longest common prefix of length 4 with t
.
+
+
+Example 2:
+
+
+
Input: s = "leetcode", t = "eetcode"
+
+
Output: 7
+
+
Explanation:
+
+
Removing s[0]
from s
results in "eetcode"
, which matches t
.
+
+
+Example 3:
+
+
+
Input: s = "one", t = "one"
+
+
Output: 3
+
+
Explanation:
+
+
No removal is needed.
+
+
+Example 4:
+
+
+
Input: s = "a", t = "b"
+
+
Output: 0
+
+
Explanation:
+
+
s
and t
cannot have a common prefix.
+
+
+
+Constraints:
+
+
+ 1 <= s.length <= 105
+ 1 <= t.length <= 105
+ s
and t
contain only lowercase English letters.
+
+
+
+
+## 解法
+
+
+
+### 方法一:双指针
+
+我们记录字符串 $s$ 和 $t$ 的长度分别为 $n$ 和 $m$,然后用两个指针 $i$ 和 $j$ 分别指向字符串 $s$ 和 $t$ 的开头,用一个布尔变量 $\textit{rem}$ 记录是否已经删除过字符。
+
+接下来,我们开始遍历字符串 $s$ 和 $t$,如果 $s[i]$ 不等于 $t[j]$,我们就判断是否已经删除过字符,如果已经删除过字符,我们就退出循环,否则我们标记已经删除过字符,然后跳过 $s[i]$;否则,我们跳过 $s[i]$ 和 $t[j]$。继续遍历,直到 $i \geq n$ 或 $j \geq m$。
+
+最后返回 $j$ 即可。
+
+时间复杂度 $O(n+m)$,其中 $n$ 和 $m$ 分别是字符串 $s$ 和 $t$ 的长度。
+
+
+
+#### Python3
+
+```python
+class Solution:
+ def longestCommonPrefix(self, s: str, t: str) -> int:
+ n, m = len(s), len(t)
+ i = j = 0
+ rem = False
+ while i < n and j < m:
+ if s[i] != t[j]:
+ if rem:
+ break
+ rem = True
+ else:
+ j += 1
+ i += 1
+ return j
+```
+
+#### Java
+
+```java
+class Solution {
+ public int longestCommonPrefix(String s, String t) {
+ int n = s.length(), m = t.length();
+ int i = 0, j = 0;
+ boolean rem = false;
+ while (i < n && j < m) {
+ if (s.charAt(i) != t.charAt(j)) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+ }
+}
+```
+
+#### C++
+
+```cpp
+class Solution {
+public:
+ int longestCommonPrefix(string s, string t) {
+ int n = s.length(), m = t.length();
+ int i = 0, j = 0;
+ bool rem = false;
+ while (i < n && j < m) {
+ if (s[i] != t[j]) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+ }
+};
+```
+
+#### Go
+
+```go
+func longestCommonPrefix(s string, t string) int {
+ n, m := len(s), len(t)
+ i, j := 0, 0
+ rem := false
+ for i < n && j < m {
+ if s[i] != t[j] {
+ if rem {
+ break
+ }
+ rem = true
+ } else {
+ j++
+ }
+ i++
+ }
+ return j
+}
+```
+
+#### TypeScript
+
+```ts
+function longestCommonPrefix(s: string, t: string): number {
+ const [n, m] = [s.length, t.length];
+ let [i, j] = [0, 0];
+ let rem: boolean = false;
+ while (i < n && j < m) {
+ if (s[i] !== t[j]) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+}
+```
+
+#### Rust
+
+```rust
+impl Solution {
+ pub fn longest_common_prefix(s: String, t: String) -> i32 {
+ let (n, m) = (s.len(), t.len());
+ let (mut i, mut j) = (0, 0);
+ let mut rem = false;
+
+ while i < n && j < m {
+ if s.as_bytes()[i] != t.as_bytes()[j] {
+ if rem {
+ break;
+ }
+ rem = true;
+ } else {
+ j += 1;
+ }
+ i += 1;
+ }
+
+ j as i32
+ }
+}
+```
+
+#### JavaScript
+
+```js
+/**
+ * @param {string} s
+ * @param {string} t
+ * @return {number}
+ */
+var longestCommonPrefix = function (s, t) {
+ const [n, m] = [s.length, t.length];
+ let [i, j] = [0, 0];
+ let rem = false;
+ while (i < n && j < m) {
+ if (s[i] !== t[j]) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+};
+```
+
+
+
+
+
+
diff --git a/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/README_EN.md b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/README_EN.md
new file mode 100644
index 0000000000000..d69d8b398493e
--- /dev/null
+++ b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/README_EN.md
@@ -0,0 +1,268 @@
+---
+comments: true
+difficulty: Medium
+edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3460.Longest%20Common%20Prefix%20After%20at%20Most%20One%20Removal/README_EN.md
+---
+
+
+
+# [3460. Longest Common Prefix After at Most One Removal 🔒](https://leetcode.com/problems/longest-common-prefix-after-at-most-one-removal)
+
+[中文文档](/solution/3400-3499/3460.Longest%20Common%20Prefix%20After%20at%20Most%20One%20Removal/README.md)
+
+## Description
+
+
+
+You are given two strings s
and t
.
+
+Return the length of the longest common prefix between s
and t
after removing at most one character from s
.
+
+Note: s
can be left without any removal.
+
+
+Example 1:
+
+
+
Input: s = "madxa", t = "madam"
+
+
Output: 4
+
+
Explanation:
+
+
Removing s[3]
from s
results in "mada"
, which has a longest common prefix of length 4 with t
.
+
+
+Example 2:
+
+
+
Input: s = "leetcode", t = "eetcode"
+
+
Output: 7
+
+
Explanation:
+
+
Removing s[0]
from s
results in "eetcode"
, which matches t
.
+
+
+Example 3:
+
+
+
Input: s = "one", t = "one"
+
+
Output: 3
+
+
Explanation:
+
+
No removal is needed.
+
+
+Example 4:
+
+
+
Input: s = "a", t = "b"
+
+
Output: 0
+
+
Explanation:
+
+
s
and t
cannot have a common prefix.
+
+
+
+Constraints:
+
+
+ 1 <= s.length <= 105
+ 1 <= t.length <= 105
+ s
and t
contain only lowercase English letters.
+
+
+
+
+## Solutions
+
+
+
+### Solution 1: Two Pointers
+
+We record the lengths of the strings $s$ and $t$ as $n$ and $m$, respectively. Then, we use two pointers $i$ and $j$ to point to the beginning of the strings $s$ and $t$, and use a boolean variable $\textit{rem}$ to record whether a character has been removed.
+
+Next, we start traversing the strings $s$ and $t$. If $s[i]$ is not equal to $t[j]$, we check if a character has already been removed. If a character has been removed, we exit the loop; otherwise, we mark that a character has been removed and skip $s[i]$. Otherwise, we skip both $s[i]$ and $t[j]$. Continue traversing until $i \geq n$ or $j \geq m$.
+
+Finally, return $j$.
+
+The time complexity is $O(n+m)$, where $n$ and $m$ are the lengths of the strings $s$ and $t$, respectively.
+
+
+
+#### Python3
+
+```python
+class Solution:
+ def longestCommonPrefix(self, s: str, t: str) -> int:
+ n, m = len(s), len(t)
+ i = j = 0
+ rem = False
+ while i < n and j < m:
+ if s[i] != t[j]:
+ if rem:
+ break
+ rem = True
+ else:
+ j += 1
+ i += 1
+ return j
+```
+
+#### Java
+
+```java
+class Solution {
+ public int longestCommonPrefix(String s, String t) {
+ int n = s.length(), m = t.length();
+ int i = 0, j = 0;
+ boolean rem = false;
+ while (i < n && j < m) {
+ if (s.charAt(i) != t.charAt(j)) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+ }
+}
+```
+
+#### C++
+
+```cpp
+class Solution {
+public:
+ int longestCommonPrefix(string s, string t) {
+ int n = s.length(), m = t.length();
+ int i = 0, j = 0;
+ bool rem = false;
+ while (i < n && j < m) {
+ if (s[i] != t[j]) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+ }
+};
+```
+
+#### Go
+
+```go
+func longestCommonPrefix(s string, t string) int {
+ n, m := len(s), len(t)
+ i, j := 0, 0
+ rem := false
+ for i < n && j < m {
+ if s[i] != t[j] {
+ if rem {
+ break
+ }
+ rem = true
+ } else {
+ j++
+ }
+ i++
+ }
+ return j
+}
+```
+
+#### TypeScript
+
+```ts
+function longestCommonPrefix(s: string, t: string): number {
+ const [n, m] = [s.length, t.length];
+ let [i, j] = [0, 0];
+ let rem: boolean = false;
+ while (i < n && j < m) {
+ if (s[i] !== t[j]) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+}
+```
+
+#### Rust
+
+```rust
+impl Solution {
+ pub fn longest_common_prefix(s: String, t: String) -> i32 {
+ let (n, m) = (s.len(), t.len());
+ let (mut i, mut j) = (0, 0);
+ let mut rem = false;
+
+ while i < n && j < m {
+ if s.as_bytes()[i] != t.as_bytes()[j] {
+ if rem {
+ break;
+ }
+ rem = true;
+ } else {
+ j += 1;
+ }
+ i += 1;
+ }
+
+ j as i32
+ }
+}
+```
+
+#### JavaScript
+
+```js
+/**
+ * @param {string} s
+ * @param {string} t
+ * @return {number}
+ */
+var longestCommonPrefix = function (s, t) {
+ const [n, m] = [s.length, t.length];
+ let [i, j] = [0, 0];
+ let rem = false;
+ while (i < n && j < m) {
+ if (s[i] !== t[j]) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+};
+```
+
+
+
+
+
+
diff --git a/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.cpp b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.cpp
new file mode 100644
index 0000000000000..154ebd4a72f8a
--- /dev/null
+++ b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.cpp
@@ -0,0 +1,20 @@
+class Solution {
+public:
+ int longestCommonPrefix(string s, string t) {
+ int n = s.length(), m = t.length();
+ int i = 0, j = 0;
+ bool rem = false;
+ while (i < n && j < m) {
+ if (s[i] != t[j]) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+ }
+};
diff --git a/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.go b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.go
new file mode 100644
index 0000000000000..fde0b8db3a0f0
--- /dev/null
+++ b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.go
@@ -0,0 +1,17 @@
+func longestCommonPrefix(s string, t string) int {
+ n, m := len(s), len(t)
+ i, j := 0, 0
+ rem := false
+ for i < n && j < m {
+ if s[i] != t[j] {
+ if rem {
+ break
+ }
+ rem = true
+ } else {
+ j++
+ }
+ i++
+ }
+ return j
+}
diff --git a/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.java b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.java
new file mode 100644
index 0000000000000..d84c929c41f35
--- /dev/null
+++ b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.java
@@ -0,0 +1,19 @@
+class Solution {
+ public int longestCommonPrefix(String s, String t) {
+ int n = s.length(), m = t.length();
+ int i = 0, j = 0;
+ boolean rem = false;
+ while (i < n && j < m) {
+ if (s.charAt(i) != t.charAt(j)) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+ }
+}
diff --git a/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.js b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.js
new file mode 100644
index 0000000000000..29935271a5f35
--- /dev/null
+++ b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.js
@@ -0,0 +1,22 @@
+/**
+ * @param {string} s
+ * @param {string} t
+ * @return {number}
+ */
+var longestCommonPrefix = function (s, t) {
+ const [n, m] = [s.length, t.length];
+ let [i, j] = [0, 0];
+ let rem = false;
+ while (i < n && j < m) {
+ if (s[i] !== t[j]) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+};
diff --git a/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.py b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.py
new file mode 100644
index 0000000000000..5f08ae1820c81
--- /dev/null
+++ b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.py
@@ -0,0 +1,14 @@
+class Solution:
+ def longestCommonPrefix(self, s: str, t: str) -> int:
+ n, m = len(s), len(t)
+ i = j = 0
+ rem = False
+ while i < n and j < m:
+ if s[i] != t[j]:
+ if rem:
+ break
+ rem = True
+ else:
+ j += 1
+ i += 1
+ return j
diff --git a/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.rs b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.rs
new file mode 100644
index 0000000000000..16e70549c01b4
--- /dev/null
+++ b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.rs
@@ -0,0 +1,21 @@
+impl Solution {
+ pub fn longest_common_prefix(s: String, t: String) -> i32 {
+ let (n, m) = (s.len(), t.len());
+ let (mut i, mut j) = (0, 0);
+ let mut rem = false;
+
+ while i < n && j < m {
+ if s.as_bytes()[i] != t.as_bytes()[j] {
+ if rem {
+ break;
+ }
+ rem = true;
+ } else {
+ j += 1;
+ }
+ i += 1;
+ }
+
+ j as i32
+ }
+}
diff --git a/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.ts b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.ts
new file mode 100644
index 0000000000000..f5a4b5ea6ef82
--- /dev/null
+++ b/solution/3400-3499/3460.Longest Common Prefix After at Most One Removal/Solution.ts
@@ -0,0 +1,17 @@
+function longestCommonPrefix(s: string, t: string): number {
+ const [n, m] = [s.length, t.length];
+ let [i, j] = [0, 0];
+ let rem: boolean = false;
+ while (i < n && j < m) {
+ if (s[i] !== t[j]) {
+ if (rem) {
+ break;
+ }
+ rem = true;
+ } else {
+ ++j;
+ }
+ ++i;
+ }
+ return j;
+}
diff --git a/solution/README.md b/solution/README.md
index 4d8a22fea6c4d..78300adad698a 100644
--- a/solution/README.md
+++ b/solution/README.md
@@ -3470,6 +3470,7 @@
| 3457 | [吃披萨](/solution/3400-3499/3457.Eat%20Pizzas%21/README.md) | | 中等 | 第 437 场周赛 |
| 3458 | [选择 K 个互不重叠的特殊子字符串](/solution/3400-3499/3458.Select%20K%20Disjoint%20Special%20Substrings/README.md) | | 中等 | 第 437 场周赛 |
| 3459 | [最长 V 形对角线段的长度](/solution/3400-3499/3459.Length%20of%20Longest%20V-Shaped%20Diagonal%20Segment/README.md) | | 困难 | 第 437 场周赛 |
+| 3460 | [Longest Common Prefix After at Most One Removal](/solution/3400-3499/3460.Longest%20Common%20Prefix%20After%20at%20Most%20One%20Removal/README.md) | | 中等 | 🔒 |
## 版权
diff --git a/solution/README_EN.md b/solution/README_EN.md
index 381467339a164..5c91e1126f9f2 100644
--- a/solution/README_EN.md
+++ b/solution/README_EN.md
@@ -3468,6 +3468,7 @@ Press Control + F(or Command + F on
| 3457 | [Eat Pizzas!](/solution/3400-3499/3457.Eat%20Pizzas%21/README_EN.md) | | Medium | Weekly Contest 437 |
| 3458 | [Select K Disjoint Special Substrings](/solution/3400-3499/3458.Select%20K%20Disjoint%20Special%20Substrings/README_EN.md) | | Medium | Weekly Contest 437 |
| 3459 | [Length of Longest V-Shaped Diagonal Segment](/solution/3400-3499/3459.Length%20of%20Longest%20V-Shaped%20Diagonal%20Segment/README_EN.md) | | Hard | Weekly Contest 437 |
+| 3460 | [Longest Common Prefix After at Most One Removal](/solution/3400-3499/3460.Longest%20Common%20Prefix%20After%20at%20Most%20One%20Removal/README_EN.md) | | Medium | 🔒 |
## Copyright