8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 602d389 commit 1277f3bCopy full SHA for 1277f3b
src/main.rs
@@ -1,2 +1,2 @@
1
-mod longest_inc_sub;
+mod partition_equal_subset;
2
fn main() {}
src/partition_equal_subset.rs
@@ -0,0 +1,23 @@
+pub struct Solution {}
+impl Solution {
3
+ pub fn can_partition(nums: Vec<i32>) -> bool {
4
+ use std::collections::HashSet;
5
+ let mut target: i32 = nums.iter().sum();
6
+ if target % 2 == 0 {
7
+ target = target / 2;
8
+ } else {
9
+ return false;
10
+ }
11
+ let mut mem: HashSet<i32> = HashSet::new();
12
+ mem.insert(0);
13
+ for i in (0..nums.len()).rev() {
14
+ if mem.contains(&target) {
15
+ return true;
16
17
+ for val in mem.clone() {
18
+ mem.insert(val + nums[i]);
19
20
21
+ false
22
23
+}
0 commit comments