当前位置:网站首页>LeetCode Daily 2 Questions 01: Reverse Strings (both 1200) Method: Double Pointer

LeetCode Daily 2 Questions 01: Reverse Strings (both 1200) Method: Double Pointer

2022-08-10 22:29:00 The man was fishing for snow in the cold river alone.

The title is as follows:

insert image description here

Method:

Solution idea: Use the double pointer method to determine the left value left and the right value right of the array, and then exchange the two-digit numbers. After each cycle, the left is shifted to the right, and the right is shifted to the left,

class Solution {public void reverseString(char[] s) {int left=0,h=(s.length-1)/2,right=s.length-1;while (left<=h){//0<2char temp=s[left];s[left]=s[right];s[right]=temp;left++;right--;}}}

insert image description here

原网站

版权声明
本文为[The man was fishing for snow in the cold river alone.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208102151155867.html