We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d7a74e3 commit 1f2bb52Copy full SHA for 1f2bb52
strings/rotate.py
@@ -0,0 +1,21 @@
1
+"""
2
+rotate("hello", 2) => "llohe"
3
+rotate("hello", 5) => "hello"
4
+rotate("hello", 6) => "elloh"
5
+rotate("hello", 7) => "llohe"
6
+complexity: O(1)
7
8
+
9
10
+def rotate(string: str, degree: int) -> str:
11
+ degree %= len(string)
12
+ double_string = string + string
13
+ return double_string[degree:degree+len(string)]
14
15
16
+if __name__ == "__main__":
17
+ print(rotate("hello", 2) == "llohe")
18
+ print(rotate("hello", 5) == "hello")
19
+ print(rotate("hello", 6) == "elloh")
20
+ print(rotate("hello", 7) == "llohe")
21
+ print(rotate("hello", 102) == "llohe")
0 commit comments