|
@@ -0,0 +1,21 @@
|
|
|
|
+struct Solution;
|
|
|
|
+
|
|
|
|
+impl Solution {
|
|
|
|
+ pub fn reverse_words(s: String) -> String {
|
|
|
|
+ s.split_whitespace().rev().collect::<Vec<&str>>().join(" ")
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#[cfg(test)]
|
|
|
|
+mod tests {
|
|
|
|
+ use super::*;
|
|
|
|
+
|
|
|
|
+ #[test]
|
|
|
|
+ fn test_reverse_words() {
|
|
|
|
+ let s = String::from("a good example");
|
|
|
|
+
|
|
|
|
+ let res = Solution::reverse_words(s);
|
|
|
|
+ assert_eq!(res, String::from( "example good a"));
|
|
|
|
+ }
|
|
|
|
+}
|