344[leetcode]C代码实现 反转字符串(Reverse String)

(一)题目描述

(二)思想方法

定义两个下表指针low,high从数组两边交换。直到low大于high

(三)代码实现

class Solution {
public:
    void reverseString(vector<char>& s) {
        int low = 0, high= s.size()-1;
	char temp;
	while (low <= high)
	{
		temp = s[high];
		s[high] = s[low];
		s[low] = temp;
        low++;
        high--;
	}
    }
};

猜你喜欢

转载自blog.csdn.net/guaiguaitinghua/article/details/90640249