public class Solution {
public String LeftRotateString(String s,int n) {
if(s == null || s.length() < 2) {
return s;
}
n %= s.length();
char[] arr = s.toCharArray();
reverse(arr, 0, s.length() - 1);
reverse(arr, s.length() - n, s.length() - 1);
reverse(arr, 0, s.length() - 1 - n);
return new String(arr);
}
public void reverse(char[] arr, int i, int j) {
while(i < j) {
swap(arr, i, j);
i++;
j--;
}
}
public void swap(char[] arr, int i, int j) {
char tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}