diff --git a/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README.md b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README.md index f4af2f9077b3a..83260e3978cad 100644 --- a/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README.md +++ b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README.md @@ -40,7 +40,7 @@ tags:
输入:nums = [5,3,6,1,12], original = 3
输出:24
-解释:
+解释:
- 3 能在 nums 中找到。3 * 2 = 6 。
- 6 能在 nums 中找到。6 * 2 = 12 。
- 12 能在 nums 中找到。12 * 2 = 24 。
@@ -152,6 +152,22 @@ function findFinalValue(nums: number[], original: number): number {
}
```
+#### Rust
+
+```rust
+impl Solution {
+ pub fn find_final_value(nums: Vec, original: i32) -> i32 {
+ use std::collections::HashSet;
+ let s: HashSet = nums.into_iter().collect();
+ let mut original = original;
+ while s.contains(&original) {
+ original <<= 1;
+ }
+ original
+ }
+}
+```
+
diff --git a/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README_EN.md b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README_EN.md
index 6d4f23cb49bf0..f5e9e66b8bf0d 100644
--- a/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README_EN.md
+++ b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/README_EN.md
@@ -39,7 +39,7 @@ tags:
Input: nums = [5,3,6,1,12], original = 3
Output: 24
-Explanation:
+Explanation:
- 3 is found in nums. 3 is multiplied by 2 to obtain 6.
- 6 is found in nums. 6 is multiplied by 2 to obtain 12.
- 12 is found in nums. 12 is multiplied by 2 to obtain 24.
@@ -150,6 +150,22 @@ function findFinalValue(nums: number[], original: number): number {
}
```
+#### Rust
+
+```rust
+impl Solution {
+ pub fn find_final_value(nums: Vec, original: i32) -> i32 {
+ use std::collections::HashSet;
+ let s: HashSet = nums.into_iter().collect();
+ let mut original = original;
+ while s.contains(&original) {
+ original <<= 1;
+ }
+ original
+ }
+}
+```
+
diff --git a/solution/2100-2199/2154.Keep Multiplying Found Values by Two/Solution.rs b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/Solution.rs
new file mode 100644
index 0000000000000..279bb167cf88b
--- /dev/null
+++ b/solution/2100-2199/2154.Keep Multiplying Found Values by Two/Solution.rs
@@ -0,0 +1,11 @@
+impl Solution {
+ pub fn find_final_value(nums: Vec, original: i32) -> i32 {
+ use std::collections::HashSet;
+ let s: HashSet = nums.into_iter().collect();
+ let mut original = original;
+ while s.contains(&original) {
+ original <<= 1;
+ }
+ original
+ }
+}