File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 2161
2161
3075|[ Maximize Happiness of Selected Children] ( ./solutions/3075-maximize-happiness-of-selected-children.js ) |Medium|
2162
2162
3076|[ Shortest Uncommon Substring in an Array] ( ./solutions/3076-shortest-uncommon-substring-in-an-array.js ) |Medium|
2163
2163
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|
2164
2165
3105|[ Longest Strictly Increasing or Strictly Decreasing Subarray] ( ./solutions/3105-longest-strictly-increasing-or-strictly-decreasing-subarray.js ) |Easy|
2165
2166
3108|[ Minimum Cost Walk in Weighted Graph] ( ./solutions/3108-minimum-cost-walk-in-weighted-graph.js ) |Hard|
2166
2167
3110|[ Score of a String] ( ./solutions/3110-score-of-a-string.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments