Skip to content

Commit 2515e7b

Browse files
committed
Solve #283
1 parent 4e09d93 commit 2515e7b

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,5 @@ mod n0273_integer_to_english_words;
215215
mod n0274_h_index;
216216
mod n0275_h_index_ii;
217217
mod n0279_perfect_squares;
218+
mod n0282_expression_add_operators;
219+
mod n0283_move_zeroes;

src/n0282_expression_add_operators.rs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* [282] Expression Add Operators
3+
*
4+
* Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value.
5+
*
6+
* Example 1:
7+
*
8+
*
9+
* Input: num = "123", target = 6
10+
* Output: ["1+2+3", "1*2*3"]
11+
*
12+
*
13+
* Example 2:
14+
*
15+
*
16+
* Input: num = "232", target = 8
17+
* Output: ["2*3+2", "2+3*2"]
18+
*
19+
* Example 3:
20+
*
21+
*
22+
* Input: num = "105", target = 5
23+
* Output: ["1*0+5","10-5"]
24+
*
25+
* Example 4:
26+
*
27+
*
28+
* Input: num = "00", target = 0
29+
* Output: ["0+0", "0-0", "0*0"]
30+
*
31+
*
32+
* Example 5:
33+
*
34+
*
35+
* Input: num = "3456237490", target = 9191
36+
* Output: []
37+
*
38+
*
39+
*/
40+
pub struct Solution {}
41+
42+
// submission codes start here
43+
44+
impl Solution {
45+
pub fn add_operators(num: String, target: i32) -> Vec<String> {
46+
vec![]
47+
}
48+
}
49+
50+
// submission codes end
51+
52+
#[cfg(test)]
53+
mod tests {
54+
use super::*;
55+
56+
#[test]
57+
fn test_282() {}
58+
}

src/n0283_move_zeroes.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* [283] Move Zeroes
3+
*
4+
* Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
5+
*
6+
* Example:
7+
*
8+
*
9+
* Input: [0,1,0,3,12]
10+
* Output: [1,3,12,0,0]
11+
*
12+
* Note:
13+
*
14+
* <ol>
15+
* You must do this in-place without making a copy of the array.
16+
* Minimize the total number of operations.
17+
* </ol>
18+
*/
19+
pub struct Solution {}
20+
21+
// submission codes start here
22+
23+
impl Solution {
24+
pub fn move_zeroes(nums: &mut Vec<i32>) {
25+
let mut last_none_zero = 0_usize;
26+
for i in 0..nums.len() {
27+
if nums[i] != 0 {
28+
nums.swap(last_none_zero, i);
29+
last_none_zero += 1;
30+
}
31+
}
32+
}
33+
}
34+
35+
// submission codes end
36+
37+
#[cfg(test)]
38+
mod tests {
39+
use super::*;
40+
41+
#[test]
42+
fn test_283() {
43+
let mut vec = vec![0,1,0,3,12];
44+
Solution::move_zeroes(&mut vec);
45+
assert_eq!(vec, vec![1,3,12,0,0]);
46+
}
47+
}

0 commit comments

Comments
 (0)