File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 9
9
| 14| [ 最长公共前缀] ( https://leetcode-cn.com/problems/longest-common-prefix/ ) | [ JavaScript] ( ./algorithms/longest-common-prefix.js ) | Easy|
10
10
| 21| [ 合并两个有序链表] ( https://leetcode-cn.com/problems/merge-two-sorted-lists/ ) | [ JavaScript] ( ./algorithms/merge-two-sorted-lists.js ) | Easy|
11
11
| 189| [ 轮转数组] ( https://leetcode-cn.com/problems/rotate-array/ ) | [ JavaScript] ( ./algorithms/rotate-array.js ) | Medium|
12
+ | 344| [ 反转字符串] ( https://leetcode-cn.com/problems/reverse-string/ ) | [ JavaScript] ( ./algorithms/reverse-string.js ) | Easy|
12
13
| 349| [ 两个数组的交集] ( https://leetcode-cn.com/problems/intersection-of-two-arrays/ ) | [ JavaScript] ( ./algorithms/intersection-of-two-arrays.js ) | Easy|
13
14
| 350| [ 两个数组的交集 II] ( https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/ ) | [ JavaScript] ( ./algorithms/intersection-of-two-arrays-ii.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ // 方法一:双指针
2
+
3
+ /**
4
+ * 反转字符串
5
+ * @param {character[] } s
6
+ * @return {void } Do not return anything, modify s in-place instead.
7
+ */
8
+ var reverseString = function ( s ) {
9
+ const len = s . length ;
10
+ let start = 0 , end = len - 1 ;
11
+
12
+ while ( start < end ) {
13
+ [ s [ start ] , s [ end ] ] = [ s [ end ] , s [ start ] ] ;
14
+ start ++ ;
15
+ end -- ;
16
+ }
17
+ } ;
You can’t perform that action at this time.
0 commit comments