File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
solution/0000-0099/0058.Length of Last Word Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,25 @@ class Solution {
85
85
}
86
86
```
87
87
88
+ ### ** Rust**
89
+
90
+ ``` rust
91
+ impl Solution {
92
+ pub fn length_of_last_word (s : String ) -> i32 {
93
+ let s = s . trim_end ();
94
+ if s . len () == 0 {
95
+ return 0 ;
96
+ }
97
+ for (i , c ) in s . char_indices (). rev () {
98
+ if c == ' ' {
99
+ return (s . len () - i - 1 ) as i32 ;
100
+ }
101
+ }
102
+ s . len () as i32
103
+ }
104
+ }
105
+ ```
106
+
88
107
### ** ...**
89
108
90
109
```
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn length_of_last_word ( s : String ) -> i32 {
3
+ let s = s. trim_end ( ) ;
4
+ if s. len ( ) == 0 {
5
+ return 0 ;
6
+ }
7
+ for ( i, c) in s. char_indices ( ) . rev ( ) {
8
+ if c == ' ' {
9
+ return ( s. len ( ) - i - 1 ) as i32 ;
10
+ }
11
+ }
12
+ s. len ( ) as i32
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments