File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 2701
2701
3445|[ Maximum Difference Between Even and Odd Frequency II] ( ./solutions/3445-maximum-difference-between-even-and-odd-frequency-ii.js ) |Hard|
2702
2702
3450|[ Maximum Students on a Single Bench] ( ./solutions/3450-maximum-students-on-a-single-bench.js ) |Easy|
2703
2703
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|
2704
2705
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|
2705
2706
3462|[ Maximum Sum With at Most K Elements] ( ./solutions/3462-maximum-sum-with-at-most-k-elements.js ) |Medium|
2706
2707
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|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments