Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1295 from zim0369/118-Pascals-Triangle
Browse files Browse the repository at this point in the history
Create 118-Pascals-Triangle.rs
  • Loading branch information
Ahmad-A0 authored Oct 21, 2022
2 parents 59bb906 + 6ede2b2 commit 0d1c388
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 118-Pascals-Triangle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
impl Solution {
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
let mut ans: Vec<Vec<i32>> = Vec::new();
for line in 1..=num_rows {
let mut c = 1;
let mut v: Vec<i32> = Vec::new();
for i in 1..=line {
v.push(c);
c = c * (line - i) / i;
}
ans.push(v.clone());
}
ans
}
}
15 changes: 15 additions & 0 deletions rust/58-Length-of-Last-Word.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
impl Solution {
pub fn length_of_last_word(s: String) -> i32 {
let s = s.trim_end();
let s: Vec<char> = s.chars().collect();
let mut ans = 0;
for i in (0..s.len()).rev() {
if !s[i].is_whitespace() {
ans += 1;
} else {
break;
}
}
ans
}
}

0 comments on commit 0d1c388

Please sign in to comment.