Skip to content

Commit 00d9bc9

Browse files
authoredMay 29, 2024··
feat: add swift implementation to lcof problem: No.58.2 (#2949)
1 parent 59b9f53 commit 00d9bc9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed
 

‎lcof/面试题58 - II. 左旋转字符串/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ public class Solution {
121121
}
122122
```
123123

124+
#### Swift
125+
126+
```swift
127+
class Solution {
128+
func reverseLeftWords(_ s: String, _ n: Int) -> String {
129+
let leftIndex = s.index(s.startIndex, offsetBy: n)
130+
let rightPart = s[leftIndex..<s.endIndex]
131+
let leftPart = s[s.startIndex..<leftIndex]
132+
return String(rightPart) + String(leftPart)
133+
}
134+
}
135+
```
136+
124137
<!-- tabs:end -->
125138

126139
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution {
2+
func reverseLeftWords(_ s: String, _ n: Int) -> String {
3+
let leftIndex = s.index(s.startIndex, offsetBy: n)
4+
let rightPart = s[leftIndex..<s.endIndex]
5+
let leftPart = s[s.startIndex..<leftIndex]
6+
return String(rightPart) + String(leftPart)
7+
}
8+
}

0 commit comments

Comments
 (0)
Please sign in to comment.