File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,400 LeetCode solutions in JavaScript
1
+ # 1,401 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
733
733
914|[ X of a Kind in a Deck of Cards] ( ./solutions/0914-x-of-a-kind-in-a-deck-of-cards.js ) |Medium|
734
734
915|[ Partition Array into Disjoint Intervals] ( ./solutions/0915-partition-array-into-disjoint-intervals.js ) |Medium|
735
735
916|[ Word Subsets] ( ./solutions/0916-word-subsets.js ) |Medium|
736
+ 917|[ Reverse Only Letters] ( ./solutions/0917-reverse-only-letters.js ) |Easy|
736
737
918|[ Maximum Sum Circular Subarray] ( ./solutions/0918-maximum-sum-circular-subarray.js ) |Medium|
737
738
919|[ Complete Binary Tree Inserter] ( ./solutions/0919-complete-binary-tree-inserter.js ) |Medium|
738
739
920|[ Number of Music Playlists] ( ./solutions/0920-number-of-music-playlists.js ) |Hard|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 917. Reverse Only Letters
3
+ * https://leetcode.com/problems/reverse-only-letters/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given a string s, reverse the string according to the following rules:
7
+ * - All the characters that are not English letters remain in the same position.
8
+ * - All the English letters (lowercase or uppercase) should be reversed.
9
+ *
10
+ * Return s after reversing it.
11
+ */
12
+
13
+ /**
14
+ * @param {string } s
15
+ * @return {string }
16
+ */
17
+ var reverseOnlyLetters = function ( s ) {
18
+ const chars = s . split ( '' ) ;
19
+ let left = 0 ;
20
+ let right = s . length - 1 ;
21
+
22
+ while ( left < right ) {
23
+ while ( left < right && ! / [ a - z A - Z ] / . test ( chars [ left ] ) ) {
24
+ left ++ ;
25
+ }
26
+ while ( left < right && ! / [ a - z A - Z ] / . test ( chars [ right ] ) ) {
27
+ right -- ;
28
+ }
29
+ [ chars [ left ] , chars [ right ] ] = [ chars [ right ] , chars [ left ] ] ;
30
+ left ++ ;
31
+ right -- ;
32
+ }
33
+
34
+ return chars . join ( '' ) ;
35
+ } ;
You can’t perform that action at this time.
0 commit comments