MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / truncate_sentence

Function truncate_sentence

1816-truncate-sentence.rs:14–17  ·  view source on GitHub ↗
(s: String, k: i32)

Source from the content-addressed store, hash-verified

12// 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
13
14pub fn truncate_sentence(s: String, k: i32) -> String {
15 let words: Vec<String> = s.split(" ").map(|word| word.to_string()).collect();
16 words[0..k as usize].join(" ")
17}
18
19fn main() {
20 println!("{:?}", truncate_sentence("Hello how are you Contestant".to_string(), 4));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected