Skip to content

Commit d5230fb

Browse files
committed
Add solution #3460
1 parent 08cfa78 commit d5230fb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,7 @@
27012701
3445|[Maximum Difference Between Even and Odd Frequency II](./solutions/3445-maximum-difference-between-even-and-odd-frequency-ii.js)|Hard|
27022702
3450|[Maximum Students on a Single Bench](./solutions/3450-maximum-students-on-a-single-bench.js)|Easy|
27032703
3452|[Sum of Good Numbers](./solutions/3452-sum-of-good-numbers.js)|Easy|
2704+
3460|[Longest Common Prefix After at Most One Removal](./solutions/3460-longest-common-prefix-after-at-most-one-removal.js)|Medium|
27042705
3461|[Check If Digits Are Equal in String After Operations I](./solutions/3461-check-if-digits-are-equal-in-string-after-operations-i.js)|Easy|
27052706
3462|[Maximum Sum With at Most K Elements](./solutions/3462-maximum-sum-with-at-most-k-elements.js)|Medium|
27062707
3463|[Check If Digits Are Equal in String After Operations II](./solutions/3463-check-if-digits-are-equal-in-string-after-operations-ii.js)|Hard|
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* 3460. Longest Common Prefix After at Most One Removal
3+
* https://leetcode.com/problems/longest-common-prefix-after-at-most-one-removal/
4+
* Difficulty: Medium
5+
*
6+
* You are given two strings s and t.
7+
*
8+
* Return the length of the longest common prefix between s and t after removing at most
9+
* one character from s.
10+
*
11+
* Note: s can be left without any removal.
12+
*/
13+
14+
/**
15+
* @param {string} s
16+
* @param {string} t
17+
* @return {number}
18+
*/
19+
var longestCommonPrefix = function(s, t) {
20+
let i = 0;
21+
let j = 0;
22+
let result = 0;
23+
let isRemoved = false;
24+
25+
while (i < s.length && j < t.length) {
26+
if (s[i] === t[j]) {
27+
i++;
28+
j++;
29+
result++;
30+
} else if (isRemoved) {
31+
return result;
32+
} else {
33+
isRemoved = true;
34+
i++;
35+
}
36+
}
37+
38+
return result;
39+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy