Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6a67535

Browse files
committed
Add solution #1750
1 parent 69de7e1 commit 6a67535

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,518 LeetCode solutions in JavaScript
1+
# 1,519 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1347,6 +1347,7 @@
13471347
1745|[Palindrome Partitioning IV](./solutions/1745-palindrome-partitioning-iv.js)|Hard|
13481348
1748|[Sum of Unique Elements](./solutions/1748-sum-of-unique-elements.js)|Easy|
13491349
1749|[Maximum Absolute Sum of Any Subarray](./solutions/1749-maximum-absolute-sum-of-any-subarray.js)|Medium|
1350+
1750|[Minimum Length of String After Deleting Similar Ends](./solutions/1750-minimum-length-of-string-after-deleting-similar-ends.js)|Medium|
13501351
1752|[Check if Array Is Sorted and Rotated](./solutions/1752-check-if-array-is-sorted-and-rotated.js)|Easy|
13511352
1764|[Form Array by Concatenating Subarrays of Another Array](./solutions/1764-form-array-by-concatenating-subarrays-of-another-array.js)|Medium|
13521353
1765|[Map of Highest Peak](./solutions/1765-map-of-highest-peak.js)|Medium|
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* 1750. Minimum Length of String After Deleting Similar Ends
3+
* https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/
4+
* Difficulty: Medium
5+
*
6+
* Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the
7+
* following algorithm on the string any number of times:
8+
* 1. Pick a non-empty prefix from the string s where all the characters in the prefix are equal.
9+
* 2. Pick a non-empty suffix from the string s where all the characters in this suffix are equal.
10+
* 3. The prefix and the suffix should not intersect at any index.
11+
* 4. The characters from the prefix and suffix must be the same.
12+
* 5. Delete both the prefix and the suffix.
13+
*
14+
* Return the minimum length of s after performing the above operation any number of times
15+
* (possibly zero times).
16+
*/
17+
18+
/**
19+
* @param {string} s
20+
* @return {number}
21+
*/
22+
var minimumLength = function(s) {
23+
let left = 0;
24+
let right = s.length - 1;
25+
26+
while (left < right && s[left] === s[right]) {
27+
const char = s[left];
28+
while (left <= right && s[left] === char) left++;
29+
while (left <= right && s[right] === char) right--;
30+
}
31+
32+
return Math.max(0, right - left + 1);
33+
};

0 commit comments

Comments
 (0)