题解 | #左旋转字符串#
左旋转字符串
https://www.nowcoder.com/practice/12d959b108cb42b1ab72cef4d36af5ec
public class Solution { public String LeftRotateString(String str, int n) { if (n == 0 || str == null || str.length() == 0) { return str; } String ret = ""; n = n % str.length(); for (int i = n; i < str.length(); ++i) { ret += str.charAt(i); } for (int i = 0; i < n; ++i) { ret += str.charAt(i); } return ret; } }
解题思想:找出n位置进行后半截拼接前半截。
#算法##算法笔记#