Skip to content

Commit

Permalink
feat: add rust solution to lcof problem: No.58 - ||
Browse files Browse the repository at this point in the history
面试题 58 - II. 左旋转字符串
  • Loading branch information
YangFong committed Jan 20, 2022
1 parent 7e42c9a commit b6057e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lcof/面试题58 - II. 左旋转字符串/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ func reverseLeftWords(s string, n int) string {
}
```

### **Rust**

```rust
impl Solution {
pub fn reverse_left_words(s: String, n: i32) -> String {
let len = s.len() as i32;
if n >= len {
return s;
}
String::from(&s[n as usize..]) + &s[..n as usize]
}
}
```

### **...**

```
Expand Down
9 changes: 9 additions & 0 deletions lcof/面试题58 - II. 左旋转字符串/Solution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
impl Solution {
pub fn reverse_left_words(s: String, n: i32) -> String {
let len = s.len() as i32;
if n >= len {
return s;
}
String::from(&s[n as usize..]) + &s[..n as usize]
}
}

0 comments on commit b6057e9

Please sign in to comment.