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

Commit 268db1b

Browse files
committed
Add solution #3083
1 parent 4e64eea commit 268db1b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,6 +2161,7 @@
21612161
3075|[Maximize Happiness of Selected Children](./solutions/3075-maximize-happiness-of-selected-children.js)|Medium|
21622162
3076|[Shortest Uncommon Substring in an Array](./solutions/3076-shortest-uncommon-substring-in-an-array.js)|Medium|
21632163
3079|[Find the Sum of Encrypted Integers](./solutions/3079-find-the-sum-of-encrypted-integers.js)|Easy|
2164+
3083|[Existence of a Substring in a String and Its Reverse](./solutions/3083-existence-of-a-substring-in-a-string-and-its-reverse.js)|Easy|
21642165
3105|[Longest Strictly Increasing or Strictly Decreasing Subarray](./solutions/3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js)|Easy|
21652166
3108|[Minimum Cost Walk in Weighted Graph](./solutions/3108-minimum-cost-walk-in-weighted-graph.js)|Hard|
21662167
3110|[Score of a String](./solutions/3110-score-of-a-string.js)|Easy|
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 3083. Existence of a Substring in a String and Its Reverse
3+
* https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/
4+
* Difficulty: Easy
5+
*
6+
* Given a string s, find any substring of length 2 which is also present in the reverse of s.
7+
*
8+
* Return true if such a substring exists, and false otherwise.
9+
*/
10+
11+
/**
12+
* @param {string} s
13+
* @return {boolean}
14+
*/
15+
var isSubstringPresent = function(s) {
16+
const reversed = s.split('').reverse().join('');
17+
18+
for (let i = 0; i < s.length - 1; i++) {
19+
const substr = s.slice(i, i + 2);
20+
if (reversed.includes(substr)) {
21+
return true;
22+
}
23+
}
24+
25+
return false;
26+
};

0 commit comments

Comments
 (0)