左旋转字符串

来源:互联网 发布:数据库毕业论文题目 编辑:程序博客网 时间:2024/05/16 10:44


题目描述

汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果。对于一个给定的字符序列S,请你把其循环左移K位后的序列输出。例如,字符序列S=”abcXYZdef”,要求输出循环左移3位后的结果,即“XYZdefabc”。是不是很简单?OK,搞定它!

public class Solution {    public String LeftRotateString(String str,int n) {         String result = null;if (str.length() < n || str.length() == 0) {result = "";} else {result = str.substring(n, str.length()) + str.substring(0, n);}return result;    }}

0 0