提交 0a3a5af7 编写于 作者: 梦境迷离's avatar 梦境迷离

rust leetcode 58

上级 f9b6e15d
......@@ -1562,4 +1562,13 @@ impl Solution {
curr_str
}
}
```
* 58 最后一个单词的长度
```rust
impl Solution {
pub fn length_of_last_word(s: String) -> i32 {
let chars: Vec<&str> = s.trim().split(' ').collect();
chars[chars.len() - 1].len() as i32
}
}
```
\ No newline at end of file
......@@ -2076,6 +2076,19 @@ fn leetcode_38() {
println!("{}", ret);
}
///最后一个单词的长度
fn leetcode_58() {
println!("leetcode_58");
impl Solution {
pub fn length_of_last_word(s: String) -> i32 {
let chars: Vec<&str> = s.trim().split(' ').collect();
chars[chars.len() - 1].len() as i32
}
}
let ret = Solution::length_of_last_word("Hello World".to_owned());
println!("{}", ret);
}
///所有方法调用
pub fn solutions() {
interview_58_2();
......@@ -2139,6 +2152,7 @@ pub fn solutions() {
leetcode_905();
leetcode_1207();
leetcode_38();
leetcode_58();
}
fn print_vec(nums: Vec<i32>) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册