Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cc30094

Browse files
committed
im a genius
1 parent 1277f3b commit cc30094

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

‎src/balanced_tree.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ impl Solution {
88
fn height(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
99
if let Some(node) = root {
1010
let node = node.borrow();
11+
node.
1112
let lh = height(node.left.clone());
1213
if lh == -1 {
1314
return -1;

‎src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
mod partition_equal_subset;
1+
mod unique_paths;
22
fn main() {}

‎src/unique_paths.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
pub struct Solution {}
2+
3+
impl Solution {
4+
pub fn unique_paths(m: i32, n: i32) -> i32 {
5+
let mut mem: Vec<Vec<i32>> = vec![vec![0; n as usize]; m as usize];
6+
mem[m as usize - 1][n as usize - 1] = 1;
7+
for i in (0..m).rev() {
8+
for k in (0..n).rev() {
9+
if k == n - 1 && i == m - 1 {
10+
continue;
11+
}
12+
let (d1, d2) = {
13+
let (mut d1, mut d2) = (0, 0);
14+
if i + 1 < m {
15+
d1 = mem[i as usize + 1][k as usize];
16+
}
17+
if k + 1 < n {
18+
d2 = mem[i as usize][k as usize + 1];
19+
}
20+
(d1, d2)
21+
};
22+
mem[i as usize][k as usize] = d1 + d2;
23+
}
24+
}
25+
mem[0][0]
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /