Skip to content

Commit fd1de1d

Browse files
authored
feat: add rust solution to lc problem: No.0118 (#1157)
1 parent 4b6d9af commit fd1de1d

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

solution/0100-0199/0118.Pascal's Triangle/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ public:
107107
};
108108
```
109109
110+
### **Rust**
111+
112+
```rust
113+
impl Solution {
114+
#[allow(dead_code)]
115+
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
116+
let mut ret_vec: Vec<Vec<i32>> = Vec::new();
117+
let mut cur_vec: Vec<i32> = Vec::new();
118+
119+
for i in 0..num_rows as usize {
120+
let mut new_vec: Vec<i32> = vec![1; i + 1];
121+
for j in 1..i {
122+
new_vec[j] = cur_vec[j - 1] + cur_vec[j];
123+
}
124+
cur_vec = new_vec.clone();
125+
ret_vec.push(new_vec);
126+
}
127+
128+
ret_vec
129+
}
130+
}
131+
```
132+
110133
### **Go**
111134

112135
```go

solution/0100-0199/0118.Pascal's Triangle/README_EN.md

+23
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ public:
8282
};
8383
```
8484
85+
### **Rust**
86+
87+
```rust
88+
impl Solution {
89+
#[allow(dead_code)]
90+
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
91+
let mut ret_vec: Vec<Vec<i32>> = Vec::new();
92+
let mut cur_vec: Vec<i32> = Vec::new();
93+
94+
for i in 0..num_rows as usize {
95+
let mut new_vec: Vec<i32> = vec![1; i + 1];
96+
for j in 1..i {
97+
new_vec[j] = cur_vec[j - 1] + cur_vec[j];
98+
}
99+
cur_vec = new_vec.clone();
100+
ret_vec.push(new_vec);
101+
}
102+
103+
ret_vec
104+
}
105+
}
106+
```
107+
85108
### **Go**
86109

87110
```go
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
impl Solution {
2+
#[allow(dead_code)]
3+
pub fn generate(num_rows: i32) -> Vec<Vec<i32>> {
4+
let mut ret_vec: Vec<Vec<i32>> = Vec::new();
5+
let mut cur_vec: Vec<i32> = Vec::new();
6+
7+
for i in 0..num_rows as usize {
8+
let mut new_vec: Vec<i32> = vec![1; i + 1];
9+
for j in 1..i {
10+
new_vec[j] = cur_vec[j - 1] + cur_vec[j];
11+
}
12+
cur_vec = new_vec.clone();
13+
ret_vec.push(new_vec);
14+
}
15+
16+
ret_vec
17+
}
18+
}

0 commit comments

Comments
 (0)