题解 | 左旋转字符串
左旋转字符串
https://www.nowcoder.com/practice/12d959b108cb42b1ab72cef4d36af5ec
import java.util.*; public class Solution { // 循环左移 // 思路:把所有的字符存入队列中,利用队列先进先出的性质来完成循环左移 public String LeftRotateString (String str, int n) { // write code here System.out.println(str.length()); if(str.length() == 0) { return ""; } Queue<Character> queue = new LinkedList<>(); for(int i = 0; i < str.length(); i++){ queue.add(str.charAt(i)); } for(int i = 0; i < n; i++){ char c = queue.poll(); queue.add(c); } StringBuilder res = new StringBuilder(); while(!queue.isEmpty()){ res.append(queue.poll()); } return res.toString(); } }