Skip to content

Commit fb64162

Browse files
committed
剑指Offer,旋转字符串
1 parent c9c2f98 commit fb64162

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* ½£Ö¸Offer£¬×óÐýת×Ö·û´®
3+
*/
4+
5+
public class LeftRotateStringSolution {
6+
7+
public static void main(String[] args) {
8+
9+
System.out.println(LeftRotateString("abcXYZdef", 3));
10+
}
11+
12+
public static String LeftRotateString(String str,int n) {
13+
14+
if(str == null || str.length() <= 0) {
15+
return str;
16+
}
17+
18+
n = n % str.length();
19+
return str.substring(n, str.length()) + str.substring(0, n);
20+
}
21+
}

0 commit comments

Comments
 (0)