文章目录
- 题目
- 方法一:连续双指针翻转
题目
方法一:连续双指针翻转
class Solution {public String reverseLeftWords(String s, int n) {StringBuffer sb = new StringBuffer(s);reverseWord(sb,0,n-1);reverseWord(sb,n,sb.length()-1);return sb.reverse().toString();}public void reverseWord(StringBuffer s , int start ,int end){while(start<end){char temp = s.charAt(start);s.setCharAt(start,s.charAt(end));s.setCharAt(end,temp);start++;end --;}}}