File tree 2 files changed +29
-6
lines changed
2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change 6
6
* @return {void } Do not return anything, modify s in-place instead.
7
7
*/
8
8
var reverseString = function ( s ) {
9
- const len = s . length ;
10
- let start = 0 , end = len - 1 ;
9
+ let left = 0 ;
10
+ let right = s . length - 1 ;
11
11
12
- while ( start < end ) {
13
- [ s [ start ] , s [ end ] ] = [ s [ end ] , s [ start ] ] ;
14
- start ++ ;
15
- end -- ;
12
+ while ( left < right ) {
13
+ [ s [ left ] , s [ right ] ] = [ s [ right ] , s [ left ] ] ;
14
+ left ++ ;
15
+ right -- ;
16
16
}
17
17
} ;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * @lc app=leetcode.cn id=344 lang=javascript
3
+ *
4
+ * [344] 反转字符串
5
+ */
6
+
7
+ // @lc code=start
8
+ /**
9
+ * @param {character[] } s
10
+ * @return {void } Do not return anything, modify s in-place instead.
11
+ */
12
+ var reverseString = function ( s ) {
13
+ let left = 0 ;
14
+ let right = s . length - 1 ;
15
+
16
+ while ( left < right ) {
17
+ [ s [ left ] , s [ right ] ] = [ s [ right ] , s [ left ] ] ;
18
+ left ++ ;
19
+ right -- ;
20
+ }
21
+ } ;
22
+ // @lc code=end
23
+
You can’t perform that action at this time.
0 commit comments