MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / rotation

Method rotation

src/main/java/com/thealgorithms/strings/Rotation.java:29–31  ·  view source on GitHub ↗

Move n characters in front of given string to the end of string time complexity: O(n) space complexity: O(n) @param s given string @param n the total characters to be moved @return string after rotation

(String s, int n)

Source from the content-addressed store, hash-verified

27 * @return string after rotation
28 */
29 public static String rotation(String s, int n) {
30 return s.substring(n) + s.substring(0, n);
31 }
32
33 /**
34 * Move {@code n} characters in front of given character array to the end of

Callers 2

testRotationMethod · 0.95
mainMethod · 0.95

Calls 1

reverseMethod · 0.95

Tested by 1

testRotationMethod · 0.76